CharacterArray.st
author Claus Gittinger <cg@exept.de>
Mon, 22 Apr 1996 15:48:18 +0200
changeset 1250 0f628432aa93
parent 1241 431675180b54
child 1252 105280fd8d72
permissions -rw-r--r--
fixed encoding/decoding for msdos & mac; added next decoder
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
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    13
ByteArray subclass:#CharacterArray
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
    14
	instanceVariableNames:''
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
    15
	classVariableNames:'PreviousMatch DecoderTables EncoderTables'
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
    16
	poolDictionaries:''
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
    17
	category:'Collections-Text'
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    18
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    19
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    20
!CharacterArray class methodsFor:'documentation'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    21
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    23
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    25
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    26
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    33
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    36
documentation
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    37
"
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    38
    CharacterArray is a superclass for all kinds of Strings (i.e.
68
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    39
    (singleByte-)Strings, TwoByteStrings and whatever comes in the future.
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    40
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    41
    As the name already implies, this class is abstract, meaning that there are
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    42
    no instances of it. All this class does is provide common protocol for 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    43
    concrete subclasses.
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    44
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    45
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    46
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    47
!CharacterArray class methodsFor:'instance creation'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    48
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    49
basicNew
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    50
    "return a new empty string"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    51
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    52
    ^ self basicNew:0
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    53
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    54
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    55
fromString:aString
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    56
    "return a copy of the argument, aString"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    57
68
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    58
    ^ (self basicNew:(aString size)) replaceFrom:1 with:aString
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    59
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    60
    "TwoByteString fromString:'hello'"
581
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    61
!
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    62
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    63
fromStringCollection:aCollectionOfStrings
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    64
    "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
    65
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    66
    ^ self fromStringCollection:aCollectionOfStrings separatedBy:''
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    67
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    68
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    69
     String fromStringCollection:#('hello' 'world' 'how' 'about' 'this')
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    70
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    71
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    72
    "Created: 20.11.1995 / 15:26:59 / cg"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    73
!
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    74
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    75
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    76
    "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
    77
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    78
    |newString first|
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    79
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    80
    newString := ''.
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    81
    first := true.
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    82
    aCollectionOfStrings do:[:s | 
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    83
	first ifFalse:[
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    84
	    newString := newString , aSeparatorString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    85
	] ifTrue:[
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    86
	    first := false
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    87
	].
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    88
	newString := newString , s
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    89
    ].
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    90
    ^ newString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    91
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    92
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    93
     String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' '
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    94
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    95
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    96
    "Created: 20.11.1995 / 15:32:17 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    97
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    98
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    99
new
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   100
    "return a new empty string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   101
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   102
    ^ self basicNew:0
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   103
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   104
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   105
!CharacterArray class methodsFor:'cleanup'!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   106
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   107
lowSpaceCleanup
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   108
    "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
   109
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   110
    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
   111
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   112
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   113
     CharacterArray lowSpaceCleanup
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   114
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   115
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   116
    "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
   117
    "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
   118
! !
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   119
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   120
!CharacterArray class methodsFor:'code tables'!
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   121
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   122
classForEncoding:encodingSymbol
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   123
    "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
   124
     by encodingSymbol"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   125
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   126
    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
   127
    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
   128
    encodingSymbol == #gb ifTrue:[^ GBEncodedString].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   129
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   130
    "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   131
    "/ 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
   132
    "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   133
    ^ String
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   134
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   135
    "Modified: 17.4.1996 / 16:18:53 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   136
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   137
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   138
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
   139
    "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
   140
     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
   141
     This is an experimental interface - unfinished"
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   142
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   143
    |table unrepresentableCharacterCode x80Table|
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   144
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   145
    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
   146
        table := DecoderTables at:encoding ifAbsent:nil.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   147
        table notNil ifTrue:[^ table].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   148
    ] ifFalse:[
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   149
        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
   150
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   151
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   152
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   153
    unrepresentableCharacterCode := 16rBF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   154
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   155
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   156
    "/ setup as identityTranslation
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   157
    "/
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   158
    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
   159
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   160
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   161
    "/ mac -> iso8859
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   162
    "/
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   163
    "/ You will loose the following characters:
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   164
    "/ - all of them will be replaced by 8F (¿)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   165
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   166
    "/  A0 (cross)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   167
    "/  A5 (dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   168
    "/  AA (tm - trademark)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   169
    "/  AD (not equal)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   170
    "/  B0 (infinity)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   171
    "/  B3 (less-double-equal <=)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   172
    "/  B4 (greater-equal >-)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   173
    "/  B6 (math lowercase delta)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   174
    "/  B7 (math sum)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   175
    "/  B8 (math uppercase pi)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   176
    "/  B9 (math lowercase pi)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   177
    "/  BA (math integral)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   178
    "/  BD (math omega)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   179
    "/  C3 (math union)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   180
    "/  C4 (ext latin f)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   181
    "/  C5 (math almost equal)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   182
    "/  C6 (math uppercase delta)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   183
    "/  C9 (dot-dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   184
    "/  CE (OE ligature)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   185
    "/  CF (oe ligature)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   186
    "/  D1 (hyphen)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   187
    "/  D2 (opening top dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   188
    "/  D3 (closing top dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   189
    "/  D4 (opening top quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   190
    "/  D5 (closing top quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   191
    "/  D7 (geometric: )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   192
    "/  D9 (uppercase Y diacrit )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   193
    "/  DA (slash2 )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   194
    "/  DC (single oldStyle opening quote (<) )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   195
    "/  DD (single oldStyle closing quote (>) )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   196
    "/  DE (? )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   197
    "/  DF (? )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   198
    "/  E0 (double cross )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   199
    "/  E2 (opening bottom quote )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   200
    "/  E3 (opening bottom dquote )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   201
    "/  F0 (? )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   202
    "/  F5 (latin l )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   203
    "/  F6 (diacrit circumflex)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   204
    "/  F7 (diacrit tilde)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   205
    "/  F8 (diacrit top line)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   206
    "/  F9 (diacrit inverse circumflex)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   207
    "/  FA (diacrit dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   208
    "/  FB (diacrit ring)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   209
    "/  FC (diacrit cedille left)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   210
    "/  FD (diacrit dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   211
    "/  FE (diacrit cedille right)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   212
    "/  FF (diacrit circumflex2 ?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   213
    "/   
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   214
    encoding == #mac ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   215
        x80Table :=
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   216
            #( 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
   217
               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
   218
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   219
               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
   220
               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
   221
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   222
               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
   223
               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
   224
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   225
               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
   226
               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
   227
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   228
               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
   229
               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
   230
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   231
               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
   232
               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
   233
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   234
               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
   235
               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
   236
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   237
               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
   238
               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
   239
            ).
657
449935f15b9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 652
diff changeset
   240
    ].
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   241
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   242
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   243
    "/ next -> iso8859
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   244
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   245
    "/ You will loose the following characters:
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   246
    "/ - all of them will be replaced by 8F (¿) 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   247
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   248
    "/  A4 (diacrit /)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   249
    "/  A9 (diacrit quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   250
    "/  AA (top opening dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   251
    "/  AC (single oldStyle opening quote (<))
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   252
    "/  AD (single oldStyle closing quote (>))
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   253
    "/  AE (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   254
    "/  AF (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   255
    "/  B2 (cross)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   256
    "/  B3 (double cross)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   257
    "/  B7 (enter dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   258
    "/  B8 (opening bottom quote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   259
    "/  B9 (opening bottom dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   260
    "/  BA (closing top dquote)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   261
    "/  BC (dot-dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   262
    "/  BD (per-mille)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   263
    "/  C0 (subscript 1)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   264
    "/  C1 (accent grave)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   265
    "/  C2 (accent degu)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   266
    "/  C3 (accent circonflex)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   267
    "/  C4 (accent tilde)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   268
    "/  C5 (accent line)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   269
    "/  C6 (accent circonflex reverse)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   270
    "/  C7 (accent dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   271
    "/  C8 (accent dot-dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   272
    "/  D0 (hline)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   273
    "/  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
   274
    "/  EA (OE ligature)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   275
    "/  F5 (latin l)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   276
    "/  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
   277
    "/  FE (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   278
    "/  FF (?)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   279
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   280
    encoding == #next ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   281
        unrepresentableCharacterCode := 16rBF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   282
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   283
        x80Table :=
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   284
            #( 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
   285
               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
   286
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   287
               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
   288
               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
   289
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   290
               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
   291
               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
   292
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   293
               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
   294
               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
   295
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   296
               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
   297
               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
   298
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   299
               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
   300
               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
   301
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   302
               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
   303
               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
   304
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   305
               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
   306
               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
   307
            ).
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   308
    ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   309
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   310
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   311
    "/ postscript -> iso8859
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   312
    "/
657
449935f15b9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 652
diff changeset
   313
    encoding == #postscript ifTrue:[
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   314
        table at:8r224+1 put:246. "/ german umlaut o (ps: 148; 8859: 246)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   315
        table at:8r204+1 put:228. "/ german umlaut a (ps: 132; 8859: 228)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   316
        table at:8r201+1 put:252. "/ german umlaut u (ps: 129; 8859: 252)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   317
        table at:8r231+1 put:214. "/ german umlaut O (ps: 153; 8859: 214)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   318
        table at:8r216+1 put:196. "/ german umlaut A (ps: 142; 8859: 196)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   319
        table at:8r232+1 put:220. "/ german umlaut U (ps: 154; 8859: 220)
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   320
        "/ more needed here - need info to do it ....
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   321
    ].
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   322
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   323
    "/
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   324
    "/ msdos (codePage 437) -> iso8859
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   325
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   326
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   327
    "/ You will loose the following characters:
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   328
    "/ - all of them will be replaced by 8F (¿) 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   329
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   330
    "/  9E      (pesetas)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   331
    "/  9F      (latin f)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   332
    "/  A9      (technical not)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   333
    "/  B0 - BF (block graphic)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   334
    "/  C0 - CF (block graphic)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   335
    "/  D0 - DF (block graphic)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   336
    "/  E0      (greek alpha)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   337
    "/  E2 - E5 (greek)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   338
    "/  E7 - EC (greek & math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   339
    "/  EE - EF (greek & math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   340
    "/  F0      (math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   341
    "/  F2 - F5 (math & technical)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   342
    "/  F7      (math)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   343
    "/  F9      (center dot)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   344
    "/  FB      (math sqrt)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   345
    "/  FC      (super n)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   346
    "/  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
   347
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   348
    encoding == #msdos ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   349
        unrepresentableCharacterCode := 16rBF.
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
        x80Table :=
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   352
            #( 16r00c7 16r00fc 16r00e9 16r00e2 16r00e4 16r00e0 16r00e5 16r00e7  "/ 80
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   353
               16r00ea 16r00eb 16r00e8 16r00ef 16r00ee 16r00ec 16r00c4 16r00c5
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   354
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   355
               16r00c9 16r00e6 16r00c6 16r00f4 16r00f6 16r00f2 16r00fb 16r00f9  "/ 90
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   356
               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
   357
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   358
               16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00da  "/ a0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   359
               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
   360
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  "/ b0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   362
               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
   363
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   364
               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
   365
               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
   366
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   367
               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
   368
               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
   369
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   370
               16rFFFF 16r00df 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00b5 16rFFFF  "/ e0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   371
               16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f8 16rFFFF 16rFFFF
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   372
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   373
               16rFFFF 16r00b1 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f7 16rFFFF  "/ f0
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   374
               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
   375
            ).
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   376
    ].
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   377
    "/ more encodings needed here ....
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   378
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   379
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   380
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   381
    "/ 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
   382
    "/ 0x80..0xFF characters
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   383
    "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   384
    x80Table notNil ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   385
        x80Table keysAndValuesDo:[:idx :repl |
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   386
            |ch|
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   387
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   388
            repl == 16rFFFF ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   389
                ch := unrepresentableCharacterCode
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   390
            ] ifFalse:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   391
                ch := repl
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   392
            ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   393
            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
   394
        ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   395
    ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   396
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   397
    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
   398
    ^ table
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   399
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   400
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   401
     DecoderTables := nil
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   402
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   403
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   404
    "Created: 20.10.1995 / 23:04:43 / cg"
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   405
    "Modified: 22.4.1996 / 15:30:10 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   406
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   407
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   408
encoderTableFor:encoding
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   409
    "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
   410
     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
   411
     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
   412
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   413
    |table decoderTable unrepresentableCharacterCode 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   414
     unrepresentableISOCharacterCode x80Table|
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   415
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   416
    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
   417
        table := EncoderTables at:encoding ifAbsent:nil.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   418
        table notNil ifTrue:[^ table].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   419
    ] ifFalse:[
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   420
        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
   421
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   422
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   423
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   424
    "/ iso8859 -> mac
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   425
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   426
    encoding == #mac ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   427
        decoderTable := self decoderTableFor:encoding.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   428
        unrepresentableCharacterCode := 16rFF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   429
        unrepresentableISOCharacterCode := 16rBF.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   430
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   431
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   432
    "/ iso8859 -> msdos
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   433
    "/
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   434
    encoding == #msdos ifTrue:[
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   435
        decoderTable := self decoderTableFor:encoding.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   436
        unrepresentableCharacterCode := 16rFF.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   437
        unrepresentableISOCharacterCode := 16rBF.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   438
    ].
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   439
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   440
    "/ 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
   441
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   442
    decoderTable notNil ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   443
        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
   444
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   445
        0 to:16rFF do:[:code |
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   446
            |isoCode destIdex|
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   447
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   448
            isoCode := decoderTable at:(code+1).
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   449
            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
   450
        ]
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   451
    ].
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   452
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   453
    table isNil ifTrue:[
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   454
        "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   455
        "/ setup as identityTranslation
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   456
        "/
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   457
        table := (0 to:255) asByteArray.
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   458
    ].
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   459
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   460
    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
   461
    ^ table
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   462
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   463
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   464
     EncoderTables := nil
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   465
     DecoderTables := nil
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   466
     CharacterArray decoderTableFor:#mac
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   467
     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
   468
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   469
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   470
    "Created: 22.2.1996 / 16:17:58 / cg"
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   471
    "Modified: 22.4.1996 / 15:42:22 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   472
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   473
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   474
supportedEncodings
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   475
    "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
   476
     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
   477
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   478
    ^ #( 
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   479
         (
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   480
          iso8859
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   481
          ascii
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   482
          msdos                   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   483
          mac         
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   484
          next   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   485
          euc   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   486
          jis   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   487
          jis7   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   488
          gb   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   489
          big5)
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   490
       )
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   491
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   492
    "Created: 22.2.1996 / 16:19:20 / cg"
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   493
    "Modified: 22.4.1996 / 14:43:50 / cg"
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   494
!
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   495
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   496
supportedExternalEncodings
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   497
    "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
   498
     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
   499
     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
   500
     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
   501
     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
   502
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   503
    ^ #( 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   504
         (
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   505
          'iso8859 (ansi)'  
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   506
          'msdos (codepage 437)'  
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   507
          'macintosh' 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   508
          'NEXT' 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   509
          'EUC (extended unix code)' 
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   510
          'JIS7 (jis 7bit escape codes)'
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   511
          'GB (mainland china hanzi)'
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   512
          'BIG5 (taiwan hanzi)'
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   513
         )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   514
         (
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   515
          iso8859
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   516
          msdos                   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   517
          mac         
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   518
          next   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   519
          euc   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   520
          jis7   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   521
          gb   
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   522
          big5)
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   523
       )
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   524
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   525
    "Created: 22.4.1996 / 14:39:39 / cg"
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
   526
    "Modified: 22.4.1996 / 14:49:34 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   527
! !
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   528
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   529
!CharacterArray class methodsFor:'encoding / decoding'!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   530
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   531
decodeFromBIG5:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   532
    "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
   533
     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
   534
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   535
     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
   536
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   537
    |newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   538
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   539
    newString := BIG5EncodedString new:aString size.
1204
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
   540
    ^ self decodeFromBIG5_or_GB:aString into:newString.
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
   541
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
   542
    "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
   543
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   544
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   545
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
   546
    "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
   547
     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
   548
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   549
     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
   550
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   551
    |sz     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   552
     dstIdx "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   553
     srcIdx "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   554
     b1     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   555
     b2     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   556
     val    "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   557
     c|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   558
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   559
    sz := aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   560
    sz ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   561
        dstIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   562
        srcIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   563
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   564
        [true] whileTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   565
            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
   566
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   567
            "/ characters below 16rA1 are left untranslated
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   568
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   569
            b1 := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   570
            b1 >= 16rA1 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   571
                srcIdx := srcIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   572
                srcIdx <= sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   573
                    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
   574
                    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
   575
                    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
   576
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   577
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   578
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   579
            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
   580
            dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   581
            srcIdx := srcIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   582
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   583
            srcIdx > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   584
                ^ 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
   585
            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   586
        ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   587
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   588
    ^ a16BitString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   589
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   590
    "Created: 17.4.1996 / 16:55:54 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   591
    "Modified: 17.4.1996 / 18:28:31 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   592
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   593
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   594
decodeFromEUC:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   595
    "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
   596
     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
   597
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   598
     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
   599
     this one only understands New-JIS.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   600
     The result is a JISEncodedString (you need a JIS 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
   601
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   602
    |newString 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   603
     sz     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   604
     dstIdx "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   605
     start  "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   606
     b1     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   607
     b2     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   608
     val    "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   609
     romans c|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   610
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   611
    romans := JISEncodedString romanJISDecoderTable.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   612
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   613
    sz := aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   614
    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
   615
    sz ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   616
        dstIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   617
        start := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   618
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   619
        [true] whileTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   620
            c := aString at:start.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   621
            b1 := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   622
            b1 < 33 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   623
                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
   624
                dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   625
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   626
                b1 < 161 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   627
                    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
   628
                    dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   629
"/                    b1 < 127 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   630
"/                        newString at:dstIdx put:(Character value:(romans at:(b1 - 32))).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   631
"/                        dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   632
"/                    ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   633
"/                        self halt:'unsupported codeSet'
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   634
"/                    ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   635
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   636
                    start := start + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   637
                    b1 := b1 - 161 + 33.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   638
                    b2 := (aString at:start) asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   639
                    b2 := b2 - 161 + 33.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   640
                    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
   641
                    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
   642
                    dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   643
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   644
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   645
            start := start + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   646
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   647
            start > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   648
                ^ 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
   649
            ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   650
        ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   651
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   652
    ^ newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   653
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   654
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   655
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   656
         'hello' decodeFromEUC 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   657
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   658
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   659
    "Created: 17.4.1996 / 16:10:22 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   660
    "Modified: 17.4.1996 / 16:48:30 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   661
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   662
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   663
decodeFromGB:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   664
    "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
   665
     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
   666
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   667
     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
   668
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   669
    |newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   670
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   671
    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
   672
    ^ 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
   673
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   674
    "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
   675
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   676
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   677
decodeFromJIS7:aString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   678
    "return a new string containing the aStrings characters,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   679
     which are interpreted as a JIS7 encoded singleByte string.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   680
     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
   681
     this one understands New-JIS and treats Old-JIS just the same.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   682
     The result is a JISEncodedString (you need a JIS 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
   683
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   684
    |newString 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   685
     sz         "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   686
     dstIdx     "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   687
     start      "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   688
     stop       "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   689
     n1 n2 n3  
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   690
     b1         "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   691
     b2         "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   692
     val        "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   693
     singleBytes romans|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   694
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   695
    romans := JISEncodedString romanJISDecoderTable.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   696
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   697
    sz := aString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   698
    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
   699
    sz ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   700
        dstIdx := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   701
        start := 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   702
        singleBytes := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   703
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   704
        [true] whileTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   705
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   706
            "/ 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
   707
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   708
            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
   709
            stop == 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   710
                stop := sz + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   711
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   712
                (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
   713
                    stop := sz + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   714
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   715
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   716
            singleBytes ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   717
                start to:(stop - 1) do:[:i |
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   718
                    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
   719
                    newString at:dstIdx put:(Character value:b1).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   720
"/                    (b1 < 33 or:[b1 > 191]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   721
"/                        newString at:dstIdx put:(Character value:b1)
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   722
"/                    ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   723
"/                        newString at:dstIdx put:(Character value:(romans at:(b1 - 32)))
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   724
"/                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   725
                    dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   726
                ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   727
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   728
                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
   729
                    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
   730
                    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
   731
                    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
   732
                    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
   733
                    dstIdx := dstIdx + 1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   734
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   735
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   736
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   737
            stop > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   738
                ^ 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
   739
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   740
            start := stop.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   741
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   742
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   743
            "/ 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
   744
            "/ - 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
   745
            "/ 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
   746
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   747
            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
   748
            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
   749
            n3 := aString at:(start + 2).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   750
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   751
            (n2 == $$ and:[n3 == $B]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   752
                singleBytes := false.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   753
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   754
                (n2 == $$ and:[n3 == $@]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   755
                    singleBytes := false.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   756
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   757
                    (n2 == $( and:[n3 == $B]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   758
                        singleBytes := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   759
                    ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   760
                        (n2 == $( and:[n3 == $J]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   761
                            singleBytes := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   762
                        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   763
                            singleBytes ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   764
                                newString at:dstIdx put:n1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   765
                                newString at:(dstIdx + 1) put:n2.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   766
                                newString at:(dstIdx + 2) put:n3.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   767
                                dstIdx := dstIdx + 3.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   768
                            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   769
                                self halt.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   770
                            ]
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
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   774
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   775
            start := start + 3.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   776
            start > sz ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   777
                ^ 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
   778
            ]
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
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   781
    ^ newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   782
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   783
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   784
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   785
         'hello' decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   786
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   787
     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
   788
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   789
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   790
         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
   791
         s decodeFromJIS7
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
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   794
         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
   795
         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
   796
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   797
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   798
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   799
         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
   800
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   801
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   802
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   803
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   804
         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
   805
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   806
         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
   807
         s decodeFromJIS7 
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
     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
   810
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   811
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   812
         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
   813
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   814
         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
   815
         s decodeFromJIS7
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
     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
   818
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   819
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   820
         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
   821
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   822
         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
   823
         s := s , '$3'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   824
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   825
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   826
     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
   827
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   828
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   829
         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
   830
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   831
         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
   832
         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
   833
         s decodeFromJIS7
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
     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
   836
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   837
         |s|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   838
         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
   839
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   840
         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
   841
         s := s , '$3'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   842
         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
   843
         s := s copyWith:$(.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   844
         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
   845
         s := s , 'hello'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   846
         s decodeFromJIS7
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   847
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   848
     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
   849
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   850
         |s t l|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   851
         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
   852
         s := s copyWith:$$.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   853
         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
   854
         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
   855
         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
   856
         s := s copyWith:$(.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   857
         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
   858
         s := s , ' kterm'.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   859
         t := s decodeFromJIS7.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   860
         l := Label new.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   861
         l label:t.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   862
         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
   863
         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
   864
         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
   865
         l realize
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   866
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   867
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   868
    "Modified: 2.3.1996 / 13:39:08 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   869
    "Created: 17.4.1996 / 16:11:57 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   870
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   871
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   872
encodeIntoBIG5withRomans:aBIG5String
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   873
    "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
   874
     The argument must be a BIG5String.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   875
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   876
     This is used translate 8bit strings and pseudoBIG5 strings 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   877
     (romans are left untranslated) into a real BIG5 encoding for drawing.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   878
     Assuming, that the ascii codePage is at 16r2100.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   879
     Doing this allows single-byte roman strings to be displayed in a BIG5 font."
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   880
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   881
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   882
     b  "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   883
     c romans newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   884
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   885
    romans := BIG5EncodedString romanBIG5DecoderTable.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   886
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   887
    sz := aBIG5String size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   888
    newString := BIG5EncodedString new:sz.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   889
    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
   890
        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
   891
        b := c asciiValue.
1203
a43528048cb8 code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents: 1202
diff changeset
   892
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   893
        (b >= 33 and:[b <= (159+32)]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   894
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   895
            "/ a roman character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   896
            "/ map to corresponding BIG5 code
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   897
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   898
            c := Character value:(romans at:b - 32).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   899
        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   900
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   901
            "/ control or a big5 character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   902
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   903
        ].
1203
a43528048cb8 code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents: 1202
diff changeset
   904
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   905
        newString at:index put:c
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   906
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   907
    ^ newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   908
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   909
    "Created: 17.4.1996 / 17:17:50 / cg"
1203
a43528048cb8 code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents: 1202
diff changeset
   910
    "Modified: 17.4.1996 / 18:55:40 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   911
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   912
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   913
encodeIntoEUC:aJISString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   914
    "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
   915
     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
   916
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   917
     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
   918
     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
   919
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   920
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   921
     b1 "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   922
     b2 "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   923
     val "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   924
     romans out|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   925
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   926
    romans := JISEncodedString romanJISDecoderTable.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   927
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   928
    sz := aJISString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   929
    sz == 0 ifTrue:[^ ''].
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
    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
   932
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   933
    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
   934
        b1 := (aJISString at:srcIndex) asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   935
        b1 < 33 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   936
            "/ a control character    
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   937
            out nextPut:(Character value:b1).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   938
        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   939
            "/ 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
   940
            "/ 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
   941
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   942
            (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
   943
                val := romans indexOf:b1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   944
                val ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   945
                    out nextPut:(Character value:(val - 1 + 33))
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   946
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   947
                    out nextPut:(Character value:(val bitShift:-8) - 33 + 161).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   948
                    out nextPut:(Character value:(val bitAnd:16rFF) - 33 + 161).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   949
                ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   950
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   951
                out nextPut:(Character value:(val bitShift:-8) - 33 + 161).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   952
                out nextPut:(Character value:(val bitAnd:16rFF) - 33 + 161).
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
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   955
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   956
    ^ out contents
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   957
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   958
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   959
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   960
         'hello' decodeFromEUC encodeIntoEUC    
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   961
    "
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
    "Modified: 2.3.1996 / 13:40:12 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   964
    "Created: 17.4.1996 / 16:13:33 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   965
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   966
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   967
encodeIntoGBwithRomans:aGBString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   968
    "return a new string with aGBStrings characters as GB encoded 16bit string,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   969
     The argument must be a GBString.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   970
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   971
     This is used translate 8bit strings and pseudoGB5 strings 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   972
     (romans are left untranslated) into a real GB encoding for drawing.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   973
     Assuming, that the ascii codePage is at 16r2100.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   974
     Doing this allows single-byte roman strings to be displayed in a GB font."
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   975
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   976
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   977
     b  "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   978
     c newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   979
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   980
    sz := aGBString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   981
    newString := GBEncodedString new:sz.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   982
    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
   983
        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
   984
        b := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   985
        (b >= 33 and:[b <= (159+32)]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   986
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   987
            "/ a roman character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   988
            "/ map to corresponding GB code
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   989
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   990
            c := Character value:(16r2100 + b).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   991
        ] ifFalse:[
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
            "/ control or a gb character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   994
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   995
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   996
        newString at:index put:c
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   997
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   998
    ^ newString
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
    "Modified: 17.4.1996 / 17:30:36 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1001
    "Created: 17.4.1996 / 17:31:48 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1002
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1003
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1004
encodeIntoJIS7:aJISString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1005
    "return a new string with aJISStrings characters as JIS7 encoded 7bit string,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1006
     The receiver must be a 16bit JIS character string.
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
     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
  1009
     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
  1010
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1011
    |sz "{ Class:SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1012
     b1 "{ Class:SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1013
     b2 val romans out inSingleByteMode c kanji roman|
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
    inSingleByteMode := true.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1016
    kanji := JISEncodedString jis7KanjiEscapeSequence.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1017
    roman := JISEncodedString jis7RomanEscapeSequence.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1018
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1019
    romans := JISEncodedString romanJISDecoderTable.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1020
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1021
    sz := aJISString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1022
    sz == 0 ifTrue:[^ ''].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1023
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1024
    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
  1025
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1026
    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
  1027
        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
  1028
        b1 := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1029
        b1 < 33 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1030
            "/ a control character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1031
            inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1032
                out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1033
                inSingleByteMode := true
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1034
            ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1035
            out nextPut:c.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1036
        ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1037
            "/ 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
  1038
            "/ 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
  1039
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1040
            (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
  1041
                val := romans indexOf:b1.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1042
                val ~~ 0 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1043
                    inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1044
                        out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1045
                        inSingleByteMode := true
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1046
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1047
                    out nextPut:(Character value:(val - 1 + 33))
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1048
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1049
                    inSingleByteMode ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1050
                        out nextPutAll:kanji.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1051
                        inSingleByteMode := false
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1052
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1053
                    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
  1054
                    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
  1055
                ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1056
            ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1057
                b1 <= 255 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1058
                    "/ 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
  1059
"/                    b1 >= 160 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1060
"/                        ('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
  1061
"/                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1062
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1063
                    inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1064
                        out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1065
                        inSingleByteMode := true
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1066
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1067
                    out nextPut:c
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1068
                ] ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1069
                    inSingleByteMode ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1070
                        out nextPutAll:kanji.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1071
                        inSingleByteMode := false
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1072
                    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1073
                    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
  1074
                    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
  1075
                ]
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1076
            ]
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
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1079
    inSingleByteMode ifFalse:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1080
        out nextPutAll:roman.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1081
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1082
    ^ out contents
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1083
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1084
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1085
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1086
         'hello' decodeFromJIS7 encodeIntoJIS7 
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
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1089
    "Modified: 2.3.1996 / 13:40:31 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1090
    "Created: 17.4.1996 / 16:17:40 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1091
!
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1092
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1093
encodeIntoJISwithRomans:aJISString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1094
    "return a new string with aJISStrings characters as JIS encoded 16bit string,
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1095
     The argument must be a JISString.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1096
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1097
     This is used translate 8bit strings and pseudoJIS strings 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1098
     (romans are left untranslated) into a real JIS encoding for drawing.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1099
     Doing this allows single-byte roman strings to be displayed in a JIS font."
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1100
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1101
    |sz "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1102
     b  "{ Class: SmallInteger }"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1103
     c romans newString|
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1104
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1105
    romans := JISEncodedString romanJISDecoderTable.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1106
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1107
    sz := aJISString size.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1108
    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
  1109
    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
  1110
        c := aJISString at:index.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1111
        b := c asciiValue.
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1112
        (b >= 33 and:[b <= (159+32)]) ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1113
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1114
            "/ a roman character
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1115
            "/ map to corresponding JIS code
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1116
            "/
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1117
            c := Character value:(romans at:b - 32).
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1118
        ] ifFalse:[
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
            "/ control or a kanji character
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
        ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1123
        newString at:index put:c
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1124
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1125
    ^ newString
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1126
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1127
    "simple:
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1128
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1129
         'hello' encodeIntoJIS 
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1130
    "
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1131
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1132
    "Created: 17.4.1996 / 17:15:23 / cg"
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  1133
    "Modified: 17.4.1996 / 17:30:59 / cg"
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
  1134
! !
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
  1135
328
claus
parents: 327
diff changeset
  1136
!CharacterArray class methodsFor:'pattern matching'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  1137
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1138
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
  1139
    "helper for match; return true if the characters from start to stop in
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1140
     aString are matching the scan in matchScan from matchStart to matchStop.
328
claus
parents: 327
diff changeset
  1141
     The matchScan is as created by asMatchScanArray.
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1142
328
claus
parents: 327
diff changeset
  1143
     This algorithm is not at all the most efficient; 
claus
parents: 327
diff changeset
  1144
     for heavy duty pattern matching, an interface (primitive) to the regex 
claus
parents: 327
diff changeset
  1145
     pattern matching package should be added."
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1146
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1147
    |matchEntry 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1148
     mStart "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1149
     mStop  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1150
     sStart "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1151
     sStop  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1152
     mSize  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1153
     sSize  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1154
     index  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1155
     quickCheck matchLast
986
c3a9f590146d removed unused locals
Claus Gittinger <cg@exept.de>
parents: 915
diff changeset
  1156
     checkChar included|
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1157
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1158
    mStart := matchStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1159
    mStop := matchStop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1160
    sStart := start.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1161
    sStop := stop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1162
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1163
    [true] whileTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1164
	mSize := mStop - mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1165
	sSize := sStop - sStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1166
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1167
	"empty strings match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1168
	(mSize == 0) ifTrue:[^ (sSize == 0)].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1169
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1170
	matchEntry := matchScanArray at:mStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1171
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1172
	"/ the most common case first:
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1173
	(sSize ~~ 0 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1174
	and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1175
	    "advance by one and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1176
	    mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1177
	    sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1178
	] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1179
	    (matchEntry == #any) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1180
		"restString empty -> no match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1181
		(sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1182
		"# matches single character"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1183
		((sSize == 1) and:[mSize == 1]) ifTrue:[^ true].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1184
		"advance by one and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1185
		mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1186
		sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1187
	    ] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1188
		(matchEntry == #anyString) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1189
		    "* alone matches anything"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1190
		    (mSize == 1) ifTrue:[^ true].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1191
		    "restString empty & matchString not empty -> no match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1192
		    (sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1193
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1194
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1195
		     try to avoid some of the recursion by checking last
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1196
		     character and continue with shortened strings if possible
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1197
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1198
		    quickCheck := false.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1199
		    (mStop >= mStart) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1200
			matchLast := matchScanArray at:mStop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1201
			(matchLast ~~ #anyString) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1202
			    (matchLast == #any) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1203
				quickCheck := true
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1204
			    ] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1205
				matchLast == (aString at:sStop) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1206
				    quickCheck := true
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1207
				] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1208
				    matchLast isString ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1209
					quickCheck := matchLast includes:(aString at:sStop)
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1210
				    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1211
				]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1212
			    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1213
			]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1214
		    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1215
		    quickCheck ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1216
			"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1217
			 no quick check possible;
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1218
			 loop over all possible substrings
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1219
			"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1220
			index := sStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1221
			[index <= sStop] whileTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1222
			    (self matchScan:matchScanArray 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1223
				  from:(mStart + 1) 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1224
				  to:mStop 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1225
				  with:aString 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1226
				  from:index 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1227
				  to:stop 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1228
				  ignoreCase:ignoreCase) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1229
				^ true
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1230
			    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1231
			    index := index + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1232
			].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1233
			^ false
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1234
		    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1235
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1236
		     quickCheck ok, advance from the right
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1237
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1238
		    mStop := mStop - 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1239
		    sStop := sStop - 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1240
		] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1241
		    (matchEntry isString) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1242
			"testString empty -> no match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1243
			(sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1244
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1245
			included := false.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1246
			"/ checkChar := aString at:sStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1247
			included := matchEntry includes:checkChar.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1248
			included ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1249
			    ignoreCase ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1250
				checkChar isUppercase ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1251
				    included := matchEntry includes:checkChar asLowercase.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1252
				] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1253
				    included := matchEntry includes:checkChar asUppercase.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1254
				]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1255
			    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1256
			].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1257
			mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1258
			mSize := mSize - 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1259
			included ifFalse:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1260
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1261
			((sSize == 1) and:[mSize == 0]) ifTrue:[^ true].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1262
			"cut off 1st char and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1263
			sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1264
		    ] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1265
			"/ must be single character
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1266
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1267
			"testString empty ?"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1268
			(sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1269
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1270
			"first characters equal ?"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1271
			"/ checkChar := aString at:sStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1272
			ignoreCase ifFalse:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1273
			(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1274
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1275
			"advance and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1276
			mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1277
			sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1278
		    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1279
		]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1280
	    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1281
	]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  1282
    ]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1283
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1284
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1285
matchScanArrayFrom:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1286
    "scan a pattern string and decompose it into a scanArray.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1287
     This is processed faster (especially with character ranges), and
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1288
     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
  1289
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1290
    |coll 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1291
     idx "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1292
     end c1 c2 matchSet previous|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1293
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1294
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1295
    idx := 1. end := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1296
    [idx <= end] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1297
	|char this|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1298
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1299
	char := aString at:idx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1300
	char == $* ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1301
	    previous ~~ #anyString ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1302
		this := #anyString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1303
	    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1304
	] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1305
	    char == $# ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1306
		previous ~~ #anyString ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1307
		    this := #any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1308
		]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1309
	    ] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1310
		char == $[ ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1311
		    matchSet := IdentitySet new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1312
		    idx := idx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1313
		    idx > end ifTrue:[^ nil].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1314
		    char := aString at:idx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1315
		    c1 := nil.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1316
		    [char ~~ $]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1317
			((char == $-) and:[c1 notNil]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1318
			    idx := idx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1319
			    idx > end ifTrue:[^ nil].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1320
			    c2 := aString at:idx.
828
a1922f7414ff Replace subotimal (to:)do: with to:do:.
Stefan Vogel <sv@exept.de>
parents: 815
diff changeset
  1321
			    c1 to:c2 do:[:c | matchSet add:c].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1322
			    c1 := nil.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1323
			    idx := idx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1324
			] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1325
			    (char ~~ $]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1326
				matchSet add:char.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1327
				c1 := char.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1328
				idx := idx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1329
			    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1330
			].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1331
			idx > end ifTrue:[^ nil].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1332
			char := aString at:idx
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1333
		    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1334
		    this := matchSet asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1335
		] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1336
		    this := char
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1337
		]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1338
	    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1339
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1340
	this notNil ifTrue:[coll add:this. previous := this].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1341
	idx := idx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1342
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1343
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1344
    ^ coll asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1345
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1346
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1347
     String matchScanArrayFrom:'*ute*'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1348
     String matchScanArrayFrom:'**ute**'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1349
     String matchScanArrayFrom:'*uter'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1350
     String matchScanArrayFrom:'[cC]#mpute[rR]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1351
     String matchScanArrayFrom:'[abcd]*'      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1352
     String matchScanArrayFrom:'[a-k]*'      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1353
     String matchScanArrayFrom:'*some*compl*ern*' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1354
     String matchScanArrayFrom:'[a-'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1355
     String matchScanArrayFrom:'[a-zA-Z]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1356
     String matchScanArrayFrom:'[a-z01234A-Z]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1357
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1358
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1359
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1360
!CharacterArray methodsFor:'Compatibility - ST/V'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1361
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1362
byteAt:index put:aByte
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1363
    "store a byte at given index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1364
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1365
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1366
    (aByte == 0) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1367
	"store a space instead"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1368
	^ super basicAt:index put:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1369
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1370
    ^ super at:index put:(Character value:aByte)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1371
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1372
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1373
replChar:oldChar with:newChar
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1374
    "return a copy of the receiver, with all oldChars replaced
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1375
     by newChar.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1376
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1377
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1378
    ^ self copy replaceAll:oldChar by:newChar
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1379
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1380
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1381
     '12345678901234567890' replChar:$0 with:$* 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1382
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1383
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1384
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1385
replChar:oldChar withString:newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1386
    "return a copy of the receiver, with all oldChars replaced
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1387
     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
  1388
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1389
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1390
    |tmpStream|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1391
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1392
    tmpStream := WriteStream on:(self class new).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1393
    self do:[:element |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1394
	element = oldChar ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1395
	    tmpStream nextPutAll:newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1396
	] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1397
	    tmpStream nextPut:element 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1398
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1399
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1400
    ^ tmpStream contents
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1401
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1402
   "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1403
     '12345678901234567890' replChar:$0 withString:'foo' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1404
     'a string with spaces' replChar:$  withString:' foo '  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1405
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1406
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1407
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1408
trimBlanks
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1409
    "return a copy of the receiver without leading
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1410
     and trailing spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1411
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1412
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1413
    ^ self withoutSpaces
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1414
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1415
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1416
     '    spaces at beginning' trimBlanks     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1417
     'spaces at end    ' trimBlanks           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1418
     '    spaces at beginning and end     ' trimBlanks    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1419
     'no spaces' trimBlanks              
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1420
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1421
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1422
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1423
!CharacterArray methodsFor:'Compatibility - VisualAge'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1424
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1425
addLineDelimiter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1426
    "replace all '\'-characters by line delimiter (cr) - characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1427
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1428
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1429
    ^ self withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1430
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1431
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1432
bindWith:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1433
    "return a copy of the receiver, where a '%1' escape is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1434
     replaced by aString.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1435
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1436
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1437
    ^ self expandPlaceholdersWith:(Array with:aString)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1438
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1439
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1440
     'do you like %1 ?' bindWith:'smalltalk'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1441
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1442
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1443
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1444
bindWith:string1 with:string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1445
    "return a copy of the receiver, where a '%1' escape is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1446
     replaced by string1 and '%2' is replaced by string2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1447
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1448
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1449
    ^ self expandPlaceholdersWith:(Array with:string1 with:string2)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1450
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1451
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1452
     'do you prefer %1 or rather %2 ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1453
	bindWith:'smalltalk' with:'c++'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1454
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1455
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1456
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1457
bindWith:str1 with:str2 with:str3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1458
    "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
  1459
     are replaced by str1, str2 and str3 respectively.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1460
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1461
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1462
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1463
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1464
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1465
     'do you prefer %1 or rather %2 (not talking about %3) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1466
	bindWith:'smalltalk' with:'c++' with:'c'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1467
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1468
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1469
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1470
bindWith:str1 with:str2 with:str3 with:str4
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1471
    "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
  1472
     are replaced by str1, str2, str3 and str4 respectively.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1473
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1474
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1475
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1476
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1477
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1478
     '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
  1479
	bindWith:'smalltalk' with:'c++' with:'c' with:'assembler'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1480
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1481
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1482
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1483
bindWithArguments:anArrayOfStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1484
    "return a copy of the receiver, where a '%i' escape
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1485
     is replaced by the coresponding string from the argument array.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1486
     '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
  1487
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1488
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1489
    ^ self expandPlaceholdersWith:anArrayOfStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1490
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1491
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1492
     'do you prefer %1 or rather %2 (not talking about %3) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1493
	bindWithArguments:#('smalltalk' 'c++' 'c')
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1494
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1495
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1496
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1497
subStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1498
    "return an array consisting of all words contained in the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1499
     Words are separated by whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1500
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1501
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1502
    ^ self asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1503
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1504
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1505
     'hello world, this is smalltalk' subStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1506
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1507
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1508
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1509
subStrings:separatorCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1510
    "return an array consisting of all words contained in the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1511
     Words are separated by separatorCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1512
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1513
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1514
    ^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1515
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1516
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1517
     'foo:bar:baz:smalltalk' subStrings:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1518
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1519
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1520
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1521
trimSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1522
    "return a copy of the receiver without leading and trailing whiteSpace"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1523
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1524
    ^ self withoutSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1525
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1526
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1527
!CharacterArray methodsFor:'character searching'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1528
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1529
includesMatchCharacters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1530
    "return true if the receiver includes any meta characters (i.e. $* or $#) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1531
     for match operations; false if not"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1532
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1533
    ^ self includesAny:'*#['
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1534
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1535
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1536
indexOfNonSeparatorStartingAt:startIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1537
    "return the index of the next non-whitespace character"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1538
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1539
    |start  "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1540
     mySize "{ Class: SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1541
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1542
    start := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1543
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1544
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1545
    start to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1546
	(self at:index) isSeparator ifFalse:[^ index]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1547
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1548
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1549
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1550
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1551
     '    hello world' indexOfNonSeparatorStartingAt:1 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1552
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1553
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1554
     |s index1 index2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1555
     s := '   foo    bar      baz'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1556
     index1 := s indexOfNonSeparatorStartingAt:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1557
     index2 := s indexOfSeparatorStartingAt:index1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1558
     s copyFrom:index1 to:index2 - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1559
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1560
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1561
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1562
indexOfSeparator
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1563
    "return the index of the first whitespace character"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1564
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1565
    ^ self indexOfSeparatorStartingAt:1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1566
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1567
    "'hello world' indexOfSeparator"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1568
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1569
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1570
indexOfSeparatorStartingAt:startIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1571
    "return the index of the next whitespace character"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1572
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1573
    |start  "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1574
     mySize "{ Class: SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1575
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1576
    start := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1577
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1578
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1579
    start to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1580
	(self at:index) isSeparator ifTrue:[^ index]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1581
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1582
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1583
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1584
    "'hello world' indexOfSeparatorStartingAt:3"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1585
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1586
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1587
!CharacterArray methodsFor:'comparing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1588
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1589
< something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1590
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1591
     receiver is less than the argument. Otherwise return false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1592
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1593
    ^ (something > self)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1594
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1595
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1596
<= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1597
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1598
     receiver is less than or equal to the argument. Otherwise return false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1599
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1600
    ^ (self > something) not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1601
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1602
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1603
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1604
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1605
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1606
     This compare does NOT ignore case differences, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1607
     therefore 'foo' = 'Foo' will return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1608
     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
  1609
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1610
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1611
     otherSize |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1612
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1613
    aString species == self species ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1614
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1615
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1616
    mySize == otherSize ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1617
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1618
    1 to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1619
	(self at:index) = (aString at:index) ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1620
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1621
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1622
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1623
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1624
     'foo' = 'Foo'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1625
     'foo' = 'bar'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1626
     'foo' = 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1627
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1628
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1629
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1630
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1631
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1632
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1633
     In contrast to ST-80, case differences are NOT ignored, thus
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1634
     'foo' > 'Foo' will return true; use #sameAs: to compare ignoring cases.. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1635
     Since this is incompatible to ST-80, this may change."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1636
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1637
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1638
     otherSize "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1639
     n         "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1640
     c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1641
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1642
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1643
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1644
    n := mySize min:otherSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1645
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1646
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1647
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1648
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1649
	c1 > c2 ifTrue:[^ true].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1650
	c1 < c2 ifTrue:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1651
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1652
    ^ mySize > otherSize
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1653
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1654
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1655
>= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1656
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1657
     receiver is greater than or equal to the argument.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1658
     Otherwise return false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1659
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1660
    ^ (something > self) not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1661
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1662
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1663
compareWith:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1664
    "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
  1665
     greater, 0 if equal and -1 if less than the argument. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1666
     Case differences are NOT ignored, thus
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1667
     'foo' compareWith: 'Foo' will return 1."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1668
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1669
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1670
     otherSize "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1671
     n         "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1672
     c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1673
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1674
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1675
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1676
    n := mySize min:otherSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1677
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1678
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1679
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1680
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1681
	c1 > c2 ifTrue:[^ 1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1682
	c1 < c2 ifTrue:[^ -1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1683
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1684
    mySize > otherSize ifTrue:[^ 1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1685
    mySize < otherSize ifTrue:[^ -1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1686
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1687
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1688
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1689
hash
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1690
    "return an integer useful as a hash-key"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1691
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1692
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1693
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1694
    REGISTER int g, val;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1695
    REGISTER unsigned char *cp, *cp0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1696
    int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1697
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  1698
    cp = __stringVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  1699
    l = __stringSize(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  1700
    if (__qClass(self) != @global(String)) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  1701
	int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1702
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1703
	cp += n;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1704
	l -= n;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1705
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1706
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1707
    /*
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1708
     * this is the dragon-book algorithm with a funny start
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1709
     * value (to give short strings a number above 8192)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1710
     */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1711
    val = 12345;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1712
    for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1713
	val = (val << 5) + (*cp & 0x1F);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1714
	if (g = (val & 0x3E000000))
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1715
	    val ^= g >> 25 /* 23 */ /* 25 */;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1716
	val &= 0x3FFFFFFF;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1717
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1718
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1719
    if (l) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1720
	l |= 1; 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1721
	val = (val * l) & 0x3FFFFFFF;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1722
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1723
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
  1724
    RETURN ( __MKSMALLINT(val) );
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1725
%}
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1726
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1727
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1728
sameAs:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1729
    "Compare the receiver with the argument like =, but ignore
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1730
     case differences. Return true or false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1731
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1732
    |mySize "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1733
     otherSize c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1734
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1735
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1736
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1737
    mySize == otherSize ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1738
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1739
    1 to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1740
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1741
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1742
	c1 == c2 ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1743
	    c1 asLowercase = c2 asLowercase ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1744
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1745
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1746
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1747
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1748
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1749
     'foo' sameAs: 'Foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1750
     'foo' sameAs: 'bar' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1751
     'foo' sameAs: 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1752
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1753
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1754
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1755
sameCharacters:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1756
    "count & return the number of characters which are the same
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1757
     (ignoring case) in the receiver and the argument, aString."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1758
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1759
    |n "{ Class: SmallInteger }"
986
c3a9f590146d removed unused locals
Claus Gittinger <cg@exept.de>
parents: 915
diff changeset
  1760
     c1 c2 cnt|
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1761
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1762
    n := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1763
    n := n min:(aString size).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1764
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1765
    cnt := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1766
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1767
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1768
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1769
	((c1 == c2)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1770
	or:[c1 asLowercase = c2 asLowercase]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1771
	    cnt := cnt + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1772
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1773
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1774
    ^ cnt
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1775
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1776
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1777
     'foobarbaz' sameCharacters: 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1778
     'foobarbaz' sameCharacters: 'Foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1779
     'foobarbaz' sameCharacters: 'baz'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1780
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1781
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1782
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1783
!CharacterArray methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1784
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1785
asArrayOfSubstrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1786
    "return an array of substrings from the receiver, interpreting
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1787
     separators (i.e. spaces & newlines) as word-delimiters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1788
     This is a compatibility method - the actual work is done in
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1789
     asCollectionOfWords."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1790
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1791
    ^ self asCollectionOfWords asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1792
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1793
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1794
     '1 one two three four 5 five' asArrayOfSubstrings  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1795
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1796
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1797
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1798
asCollectionOfLines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1799
    "return a collection containing the lines (separated by cr) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1800
     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
  1801
     contain empty strings."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1802
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1803
    ^ self asCollectionOfSubstringsSeparatedBy:Character cr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1804
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1805
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1806
     '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
  1807
     '1 one\\\\2 two\3 three' withCRs asCollectionOfLines  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1808
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1809
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1810
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1811
asCollectionOfSubstringsSeparatedBy:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1812
    "return a collection containing the lines (separated by aCharacter) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1813
     of the receiver. If aCharacter occurs multiple times in a row, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1814
     the result will contain empty strings."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1815
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1816
    |lines myClass
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1817
     numberOfLines "{ Class:SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1818
     startIndex    "{ Class:SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1819
     stopIndex     "{ Class:SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1820
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1821
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1822
     count first, to avoid regrowing of the OC
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1823
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1824
    numberOfLines := (self occurrencesOf:aCharacter) + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1825
    lines := OrderedCollection new:numberOfLines.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1826
    myClass := self species.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1827
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1828
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1829
    1 to:numberOfLines do:[:lineNr |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1830
	stopIndex := self indexOf:aCharacter startingAt:startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1831
	stopIndex == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1832
	    stopIndex := self size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1833
	] ifFalse: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1834
	    stopIndex := stopIndex - 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1835
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1836
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1837
	(stopIndex < startIndex) ifTrue: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1838
	    lines add:(myClass new:0)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1839
	] ifFalse: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1840
	    lines add:(self copyFrom:startIndex to:stopIndex)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1841
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1842
	startIndex := stopIndex + 2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1843
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1844
    ^ lines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1845
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1846
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1847
     '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
  1848
     '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
  1849
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1850
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1851
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1852
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1853
    "return a collection containing the words (separated by any character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1854
     from aCollectionOfSeparators) of the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1855
     This allows breaking up strings using any character as separator."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1856
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1857
    |words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1858
     start  "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1859
     stop   "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1860
     mySize "{ Class:SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1861
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1862
    words := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1863
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1864
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1865
    [start <= mySize] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1866
	"skip multiple separators"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1867
	[aCollectionOfSeparators includes:(self at:start)] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1868
	    start := start + 1 .
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1869
	    start > mySize ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1870
		^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1871
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1872
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1873
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1874
	stop := self indexOfAny:aCollectionOfSeparators startingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1875
	stop == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1876
	    words add:(self copyFrom:start to:mySize).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1877
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1878
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1879
	words add:(self copyFrom:start to:(stop - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1880
	start := stop
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1881
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1882
    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1883
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1884
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1885
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1886
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1887
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1888
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1889
     'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1890
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1891
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1892
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1893
asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1894
    "return a collection containing the words (separated by whitespace) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1895
     of the receiver. Multiple occurences of whitespace characters will
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1896
     be treated like one - i.e. whitespace is skipped."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1897
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1898
    |words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1899
     start  "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1900
     stop   "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1901
     mySize "{ Class:SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1902
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1903
    words := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1904
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1905
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1906
    [start <= mySize] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1907
	start := self indexOfNonSeparatorStartingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1908
	start == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1909
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1910
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1911
	stop := self indexOfSeparatorStartingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1912
	stop == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1913
	    words add:(self copyFrom:start to:mySize).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1914
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1915
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1916
	words add:(self copyFrom:start to:(stop - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1917
	start := stop
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1918
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1919
    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1920
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1921
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1922
     'hello world isnt this nice' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1923
     '    hello    world   isnt   this   nice  ' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1924
     'hello' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1925
     '' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1926
     '      ' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1927
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1928
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1929
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1930
asComposedText
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1931
    ^ ComposedText fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1932
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1933
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1934
asFilename
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1935
    "return a Filename with pathname taken from the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1936
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1937
    ^ Filename named:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1938
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1939
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1940
asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1941
    "read a float number from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1942
     Notice, that errors may occur during the read, so you better
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1943
     setup some signal handler when using this method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1944
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1945
    ^ (Number readFromString:self) asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1946
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
     '0.123' asFloat 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1949
     '12345' asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1950
     '(1/5)' asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1951
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1952
    "
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1955
asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1956
    "read an integer from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1957
     Notice, that errors may occur during the read, so you better
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1958
     setup some signal handler when using this method."
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
    ^ Integer readFromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1961
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1962
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1963
     '12345678901234567890' asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1964
     '-1234' asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1965
     '0.123' asInteger   <- reader stops at ., returning 0 here
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1966
     '0.123' asNumber    <- returns what you expect
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1967
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1968
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1969
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1970
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1971
asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1972
    "return a copy of myself in lowercase letters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1973
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1974
    |newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1975
     mySize "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1976
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1977
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1978
    newStr := self species new:mySize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1979
    1 to:mySize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1980
	newStr at:i put:(self at:i) asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1981
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1982
    ^ newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1983
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1984
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1985
     'HelloWorld' asLowercase   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1986
     'HelloWorld' asLowercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1987
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1988
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1989
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1990
asLowercaseFirst
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1991
    "return a copy of myself where the first character is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1992
     converted to lowercase."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1993
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1994
    |newString sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1995
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1996
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1997
    newString := self copyFrom:1 to:sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1998
    sz > 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1999
	newString at:1 put:(newString at:1) asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2000
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2001
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2002
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2003
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2004
     'HelloWorld' asLowercase   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2005
     'HelloWorld' asLowercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2006
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2007
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2008
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2009
asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2010
    "read a number from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2011
     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
  2012
     so you better setup some signal handler when using this method.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2013
     This may change if ANSI specifies it."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2014
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2015
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2016
"/  ^ Number readFromString:self onError:0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2017
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2018
    ^ Number readFromString:self
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
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2021
     '123'     asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2022
     '123.567' asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2023
     '(5/6)'   asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2024
     'foo'     asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2025
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2026
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2027
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2028
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2029
asNumberFromFormatString:ignored
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2030
    "read a number from the receiver, ignoring any nonDigit characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2031
     This is typically used to convert from strings which include
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2032
     dollar-signs or millenium digits. However, this method also ignores
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2033
     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
  2034
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2035
    |tempString|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2036
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2037
    tempString := self collect:[:char | char isDigit].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2038
    ^ Number readFromString:tempString onError:0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2039
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2040
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2041
     'USD 123' asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2042
     'DM 123'  asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2043
     '123'     asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2044
     '123.567' asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2045
     '(5/6)'   asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2046
     'foo'     asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2047
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2048
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2049
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2050
asSingleByteString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2051
    "return the receiver converted to a 'normal' string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2052
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2053
    ^ String fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2054
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2055
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2056
asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2057
    "return myself - I am a string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2058
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2059
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2060
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2061
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2062
asStringCollection
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2063
    "return a collection of lines from myself."
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
    ^ StringCollection from:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2066
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2067
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2068
asTwoByteString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2069
    "return the receiver converted to a two-byte string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2070
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2071
    ^ TwoByteString fromString:self
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
asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2075
    "return a copy of myself in uppercase letters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2076
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2077
    |newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2078
     mySize "{ Class: SmallInteger }" |
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
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2081
    newStr := self species new:mySize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2082
    1 to:mySize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2083
	newStr at:i put:(self at:i) asUppercase
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
    ^ newStr
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
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2088
     'helloWorld' asUppercase      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2089
     'helloWorld' asUppercaseFirst 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2090
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2091
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2092
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2093
asUppercaseFirst
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2094
    "return a copy of myself where the first character is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2095
     converted to uppercase."
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
    |newString sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2098
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2099
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2100
    newString := self copyFrom:1 to:sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2101
    sz > 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2102
	newString at:1 put:(newString at:1) asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2103
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2104
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2105
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2106
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2107
     'helloWorld' asUppercase      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2108
     'helloWorld' asUppercaseFirst 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2109
     'HelloWorld' asUppercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2110
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2111
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2112
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2113
string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2114
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2115
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2116
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2117
tokensBasedOn:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2118
    "this is an ST-80 alias for the ST/X method
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2119
	asCollectionOfSubstringsSeparatedBy:"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2120
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2121
    ^ self asCollectionOfSubstringsSeparatedBy:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2122
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2123
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2124
     'hello:world:isnt:this nice' tokensBasedOn:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2125
     'foo,bar,baz' tokensBasedOn:$,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2126
     '/etc/passwd' asFilename readStream nextLine tokensBasedOn:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2127
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2128
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2129
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2130
!CharacterArray methodsFor:'copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2131
1050
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2132
, aStringOrCharacter
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2133
    "redefined to allow characters to be appended.
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2134
     This is nonStandard, but convenient"
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2135
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2136
    aStringOrCharacter isCharacter ifTrue:[
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2137
        ^ self , aStringOrCharacter asString
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2138
    ].
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2139
    ^ super , aStringOrCharacter
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2140
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2141
    "
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2142
     'hello' , $1    
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2143
     'hello' , '1'   
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2144
    "
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2145
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2146
    "Modified: 29.2.1996 / 20:37:36 / cg"
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2147
!
2f14bbd792a9 , now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
  2148
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2149
concatenate:string1 and:string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2150
    "return the concatenation of myself and the arguments, string1 and string2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2151
     This is equivalent to self , string1 , string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2152
     - 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
  2153
     is known to be a string."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2154
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2155
    ^ self , string1 , string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2156
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2157
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2158
concatenate:string1 and:string2 and:string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2159
    "return the concatenation of myself and the string arguments.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2160
     This is equivalent to self , string1 , string2 , string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2161
     - 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
  2162
     is known to be a string."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2163
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2164
    ^ self , string1 , string2 , string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2165
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2166
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2167
!CharacterArray methodsFor:'displaying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2168
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2169
displayOn:aGc x:x y:y
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2170
    "display the receiver in a graphicsContext - this method allows
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2171
     strings to be used like DisplayObjects."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2172
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2173
    ^ aGc displayString:self x:x y:y.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2174
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2175
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2176
!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
  2177
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2178
decodeFrom:encodingSymbol
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2179
    "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
  2180
     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
  2181
     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
  2182
     (and those are untested/incomplete):
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2183
        #euc
997
6c7f1815ed02 more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents: 991
diff changeset
  2184
        #jis7
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2185
        #mac
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2186
        #msdos
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2187
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2188
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2189
    |newString|
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2190
997
6c7f1815ed02 more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents: 991
diff changeset
  2191
    encodingSymbol == #jis7 ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2192
        ^ self class decodeFromJIS7:self
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2193
    ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2194
    encodingSymbol == #euc ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2195
        ^ self class decodeFromEUC:self
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2196
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2197
    encodingSymbol == #big5 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2198
        ^ self class 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
  2199
    ].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2200
    encodingSymbol == #gb ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2201
        ^ self class decodeFromGB:self
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2202
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2203
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2204
    newString := self class new:self size.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2205
    newString replaceFrom:self decode:encodingSymbol.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2206
    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
  2207
    ^ newString
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2208
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2209
    "Created: 22.2.1996 / 15:06:49 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2210
    "Modified: 17.4.1996 / 18:25:17 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2211
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2212
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2213
encodeInto:encodingSymbol
997
6c7f1815ed02 more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents: 991
diff changeset
  2214
    "given the receiver in internal ST/X (ISO8859) encoding, 
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2215
     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
  2216
     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
  2217
     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
  2218
     (and those are untested/incomplete):
1006
19aa191ec8e3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1005
diff changeset
  2219
        #euc
19aa191ec8e3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1005
diff changeset
  2220
        #jis7
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2221
        #mac
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2222
        #msdos
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2223
    "
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2224
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2225
    |newString|
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2226
1204
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
  2227
"/  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
  2228
1028
234d62b7f4fe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1027
diff changeset
  2229
    encodingSymbol isNil ifTrue:[^ self].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2230
    encodingSymbol == self encoding ifTrue:[^ self].
1028
234d62b7f4fe checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1027
diff changeset
  2231
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2232
    encodingSymbol == #jis7 ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2233
        ^ self class encodeIntoJIS7:self
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2234
    ].
1013
0e54ddc990cb more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents: 1012
diff changeset
  2235
    (encodingSymbol startsWith:'jis') ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2236
        ^ self class encodeIntoJISwithRomans:self
1013
0e54ddc990cb more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents: 1012
diff changeset
  2237
    ].
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2238
    encodingSymbol == #euc ifTrue:[
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2239
        ^ self class encodeIntoEUC:self
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2240
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2241
    encodingSymbol == #big5 ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2242
        ^ self class encodeIntoBIG5:self
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2243
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2244
    (encodingSymbol startsWith:'big5') ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2245
        ^ self class encodeIntoBIG5withRomans:self
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  2246
    ].
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2247
    encodingSymbol == #gb ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2248
        ^ self class encodeIntoGB:self
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2249
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2250
    (encodingSymbol startsWith:'gb') ifTrue:[
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2251
        ^ self class encodeIntoGBwithRomans:self
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2252
    ].
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2253
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2254
    newString := self class new:self size.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2255
    newString replaceFrom:self encode:encodingSymbol.
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2256
    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
  2257
    ^ newString
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2258
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2259
    "Created: 22.2.1996 / 15:07:31 / cg"
1204
977e83b2c166 oops - leftover prints
Claus Gittinger <cg@exept.de>
parents: 1203
diff changeset
  2260
    "Modified: 17.4.1996 / 18:59:12 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2261
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2262
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2263
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
  2264
    "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
  2265
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2266
    ^ 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
  2267
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2268
    "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
  2269
    "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
  2270
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2271
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2272
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
  2273
    "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
  2274
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2275
    ^ 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
  2276
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2277
    "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
  2278
    "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
  2279
!
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2280
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2281
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
  2282
    "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
  2283
     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
  2284
1023
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2285
    |sz|
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2286
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2287
    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
  2288
    encodingTable isNil ifTrue:[^ self].
1023
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2289
    sz := encodingTable size.
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2290
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2291
    1 to:self size do:[:index |
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2292
        |char oldCode newCode|
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2293
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2294
        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
  2295
        oldCode := char asciiValue.
1023
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2296
        oldCode >= sz ifFalse:[
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2297
            newCode := encodingTable at:(oldCode + 1).
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2298
            newCode ~~ oldCode ifTrue:[
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2299
                self at:index put:(Character value:newCode)
5ee2a2372aca 16bit coding
Claus Gittinger <cg@exept.de>
parents: 1018
diff changeset
  2300
            ]
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2301
        ]
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2302
    ].
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2303
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2304
    "Created: 22.2.1996 / 16:07:26 / cg"
1202
200f7cd0a457 moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
  2305
    "Modified: 17.4.1996 / 16:06:30 / cg"
991
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2306
! !
f0b45a4b82d2 first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
  2307
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2308
!CharacterArray methodsFor:'padded copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2309
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2310
centerPaddedTo:newSize
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2311
     "return a new string consisting of the receivers characters,
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2312
     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
  2313
     the resulting string.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2314
     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
  2315
     the original receiver is returned unchanged."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2316
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2317
     ^ self centerPaddedTo:newSize with:(Character space)
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2318
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2319
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2320
     'foo' centerPaddedTo:10            
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2321
     123 printString centerPaddedTo:10 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2322
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2323
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2324
    "Created: 25.11.1995 / 10:53:57 / cg"
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2325
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2326
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2327
centerPaddedTo:size with:padCharacter
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2328
    "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
  2329
     centered (i.e. padded on both sides).
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2330
     Characters are filled with padCharacter.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2331
     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
  2332
     the original receiver is returned unchanged."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2333
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2334
    |len s|
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2335
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2336
    len := self size.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2337
    (len < size) ifTrue:[
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2338
	s := self species new:size withAll:padCharacter.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2339
	s replaceFrom:(size - len) // 2  + 1 with:self.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2340
	^ s
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2341
    ]
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2342
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2343
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2344
     'foo' centerPaddedTo:11 with:$.     
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2345
     'fooBar' centerPaddedTo:5 with:$.      
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2346
     123 printString centerPaddedTo:10 with:$.        
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2347
     (' ' , 123 printString) centerPaddedTo:10 with:$.        
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2348
     (Float pi printString) centerPaddedTo:15 with:(Character space)  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2349
     (Float pi printString) centerPaddedTo:15 with:$-           
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2350
     (' ' , Float pi class name) centerPaddedTo:15 with:$.     
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2351
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2352
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2353
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2354
decimalPaddedTo:size and:afterPeriod at:decimalCharacter
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2355
    "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
  2356
     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
  2357
     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
  2358
     to be padded).
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2359
     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
  2360
     the original receiver is returned unchanged.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2361
     (sounds complicated ? -> see examples below)."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2362
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2363
    ^ self 
915
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2364
	decimalPaddedTo:size 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2365
	and:afterPeriod 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2366
	at:decimalCharacter
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2367
	withLeft:(Character space)
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2368
	right:$0
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2369
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2370
    "                                                    
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2371
     '123' decimalPaddedTo:10 and:3 at:$.      -> '   123    '  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2372
     '123' decimalPaddedTo:10 and:3 at:$.      -> '   123.000'  
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2373
     '123.' decimalPaddedTo:10 and:3 at:$.     -> '   123.000' 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2374
     '123.1' decimalPaddedTo:10 and:3 at:$.    -> '   123.100'
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2375
     '123.1' decimalPaddedTo:10 and:3 at:$.    -> '   123.1  ' 
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2376
     '123.123' decimalPaddedTo:10 and:3 at:$.  -> '   123.123'
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2377
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2378
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2379
    "Created: 23.12.1995 / 13:11:52 / cg"
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2380
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2381
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2382
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
  2383
    "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
  2384
     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
  2385
     of the period.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2386
     Characters on the left are filled with leftPadChar.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2387
     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
  2388
     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
  2389
     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
  2390
     the original receiver is returned unchanged.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2391
     (sounds complicated ? -> see examples below)."
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2392
986
c3a9f590146d removed unused locals
Claus Gittinger <cg@exept.de>
parents: 915
diff changeset
  2393
    |s idx n|
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2394
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2395
    idx := self indexOf:decimalCharacter.
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2396
    idx == 0 ifTrue:[
915
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2397
	"/
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2398
	"/ no decimal point found; adjust string to the left of the period column
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2399
	"/
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2400
	rightPadChar isNil ifTrue:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2401
	    s := self , (self species new:afterPeriod + 1 withAll:leftPadChar)
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2402
	] ifFalse:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2403
	    s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar).
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2404
	].
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2405
    ] ifFalse:[
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2406
915
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2407
	"/ the number of after-decimalPoint characters
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2408
	n := self size - idx.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2409
	rightPadChar isNil ifTrue:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2410
	    s := self , (self species new:afterPeriod - n withAll:leftPadChar).
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2411
	] ifFalse:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2412
	    s := self , (self species new:afterPeriod - n withAll:rightPadChar).
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  2413
	].
815
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2414
    ].
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2415
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2416
    ^ s leftPaddedTo:size with:leftPadChar
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2417
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2418
    "                                                    
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2419
     '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
  2420
     '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
  2421
     '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
  2422
     '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
  2423
     '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
  2424
     '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
  2425
    "
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2426
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2427
    "Modified: 23.12.1995 / 13:08:18 / cg"
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2428
!
997a02c135e7 support for decimal padding added
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2429
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2430
leftPaddedTo:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2431
    "return a new string of length size, which contains the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2432
     right-adjusted (i.e. padded on the left).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2433
     Characters on the left are filled with spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2434
     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
  2435
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2436
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2437
    ^ self leftPaddedTo:size with:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2438
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
     'foo' leftPaddedTo:10  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2441
     'fooBar' leftPaddedTo:5      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2442
     123 printString leftPaddedTo:10        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2443
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2444
!
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
leftPaddedTo:size with:padCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2447
    "return a new string of length size, which contains the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2448
     right-adjusted (i.e. padded on the left).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2449
     Characters on the left are filled with padCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2450
     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
  2451
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2452
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2453
    |len s|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2454
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2455
    len := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2456
    (len < size) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2457
	s := self species new:size withAll:padCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2458
	s replaceFrom:(size - len + 1) with:self.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2459
	^ s
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2460
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2461
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2462
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2463
     'foo' leftPaddedTo:10 with:$.      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2464
     'fooBar' leftPaddedTo:5 with:$.      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2465
     123 printString leftPaddedTo:10 with:$.        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2466
     (' ' , 123 printString) leftPaddedTo:10 with:$.        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2467
     (Float pi printString) leftPaddedTo:15 with:(Character space)  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2468
     (Float pi printString) leftPaddedTo:15 with:$-           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2469
     (' ' , Float pi class name) leftPaddedTo:15 with:$.     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2470
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2471
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2472
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2473
paddedTo:newSize
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2474
     "return a new string consisting of the receivers characters,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2475
     plus spaces up to length.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2476
     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
  2477
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2478
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2479
     ^ self paddedTo:newSize with:(Character space)
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
     'foo' paddedTo:10            
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2483
     123 printString paddedTo:10 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2484
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2485
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2486
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2487
paddedTo:newSize with:padCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2488
    "return a new string consisting of the receivers characters,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2489
     plus pad characters up to length.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2490
     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
  2491
     the  original receiver is returned unchanged."
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
    |s len|
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
    len := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2496
    len < newSize ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2497
	s := self species new:newSize withAll:padCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2498
	s replaceFrom:1 to:len with:self.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2499
	^ s
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2500
    ]
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' paddedTo:10 with:$.             
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2504
     123 printString paddedTo:10 with:$*   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2505
     (Float pi printString) paddedTo:15 with:(Character space)  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2506
     (Float pi printString) paddedTo:15 with:$-  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2507
     (Float pi class name , ' ') paddedTo:15 with:$.  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2508
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2509
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2510
328
claus
parents: 327
diff changeset
  2511
!CharacterArray methodsFor:'pattern matching'!
claus
parents: 327
diff changeset
  2512
claus
parents: 327
diff changeset
  2513
findMatchString:matchString
368
a3c21a89ec37 *** empty log message ***
claus
parents: 360
diff changeset
  2514
    "like findString/indexOfSubCollection, but allowing match patterns.
328
claus
parents: 327
diff changeset
  2515
     find matchstring; if found, return the index;
claus
parents: 327
diff changeset
  2516
     if not found, return 0."
claus
parents: 327
diff changeset
  2517
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  2518
    ^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 
328
claus
parents: 327
diff changeset
  2519
!
claus
parents: 327
diff changeset
  2520
claus
parents: 327
diff changeset
  2521
findMatchString:matchString startingAt:index
claus
parents: 327
diff changeset
  2522
    "like findString, but allowing match patterns.
claus
parents: 327
diff changeset
  2523
     find matchstring, starting at index. if found, return the index;
claus
parents: 327
diff changeset
  2524
     if not found, return 0."
claus
parents: 327
diff changeset
  2525
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  2526
    ^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 
328
claus
parents: 327
diff changeset
  2527
!
claus
parents: 327
diff changeset
  2528
claus
parents: 327
diff changeset
  2529
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock
claus
parents: 327
diff changeset
  2530
    "like findString, but allowing match patterns.
claus
parents: 327
diff changeset
  2531
     find matchstring, starting at index. if found, return the index;
claus
parents: 327
diff changeset
  2532
     if not found, return the result of evaluating exceptionBlock.
claus
parents: 327
diff changeset
  2533
     This is a q&d hack - not very efficient"
claus
parents: 327
diff changeset
  2534
claus
parents: 327
diff changeset
  2535
    |firstChar 
claus
parents: 327
diff changeset
  2536
     startIndex "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  2537
     matchSize  "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  2538
     mySize     "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  2539
     realMatchString|
claus
parents: 327
diff changeset
  2540
claus
parents: 327
diff changeset
  2541
    matchSize := matchString size.
claus
parents: 327
diff changeset
  2542
    matchSize == 0 ifTrue:[^ index]. "empty string matches"
claus
parents: 327
diff changeset
  2543
claus
parents: 327
diff changeset
  2544
    realMatchString := matchString.
claus
parents: 327
diff changeset
  2545
    (realMatchString endsWith:$*) ifFalse:[
claus
parents: 327
diff changeset
  2546
	realMatchString := realMatchString , '*'.
claus
parents: 327
diff changeset
  2547
	matchSize := matchSize + 1
claus
parents: 327
diff changeset
  2548
    ].
claus
parents: 327
diff changeset
  2549
claus
parents: 327
diff changeset
  2550
    mySize := self size.
claus
parents: 327
diff changeset
  2551
    firstChar := realMatchString at:1.
claus
parents: 327
diff changeset
  2552
claus
parents: 327
diff changeset
  2553
    firstChar asString includesMatchCharacters ifTrue:[
claus
parents: 327
diff changeset
  2554
	index to:mySize do:[:col |
claus
parents: 327
diff changeset
  2555
	    (realMatchString match:self from:col to:mySize ignoreCase:ignoreCase)
claus
parents: 327
diff changeset
  2556
	    ifTrue:[^ col]
claus
parents: 327
diff changeset
  2557
	].
claus
parents: 327
diff changeset
  2558
	^ exceptionBlock value.
claus
parents: 327
diff changeset
  2559
    ].
claus
parents: 327
diff changeset
  2560
    startIndex := self indexOf:firstChar startingAt:index.
claus
parents: 327
diff changeset
  2561
    [startIndex == 0] whileFalse:[
claus
parents: 327
diff changeset
  2562
	(realMatchString match:self from:startIndex to:mySize ignoreCase:ignoreCase)
claus
parents: 327
diff changeset
  2563
	ifTrue:[^ startIndex].
claus
parents: 327
diff changeset
  2564
	startIndex := self indexOf:firstChar startingAt:(startIndex + 1)
claus
parents: 327
diff changeset
  2565
    ].
claus
parents: 327
diff changeset
  2566
    ^ exceptionBlock value
claus
parents: 327
diff changeset
  2567
claus
parents: 327
diff changeset
  2568
    "
claus
parents: 327
diff changeset
  2569
     'one two three four' findMatchString:'o[nu]'
claus
parents: 327
diff changeset
  2570
     'one two three four' findMatchString:'o[nu]' startingAt:3
claus
parents: 327
diff changeset
  2571
    "
claus
parents: 327
diff changeset
  2572
!
claus
parents: 327
diff changeset
  2573
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2574
includesMatchString:matchString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2575
    "like includesString, but allowing match patterns.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2576
     find matchstring; if found, return true, otherwise return false"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2577
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2578
    ^ (self findMatchString:matchString) ~~ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2579
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2580
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2581
     'hello world' includesMatchString:'h*'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2582
     'hello world' includesMatchString:'h[aeiou]llo' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2583
     'hello world' includesMatchString:'wor*'     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2584
     'hello world' includesMatchString:'woR*'     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2585
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2586
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2587
328
claus
parents: 327
diff changeset
  2588
match:aString
claus
parents: 327
diff changeset
  2589
    "return true if aString matches self, where self may contain meta-match 
claus
parents: 327
diff changeset
  2590
     characters $* (to match any string) or $# (to match any character).
claus
parents: 327
diff changeset
  2591
     or [...] to match a set of characters.
345
claus
parents: 343
diff changeset
  2592
     Lower/uppercase are considered different.
claus
parents: 343
diff changeset
  2593
     NOTICE: match-meta character interpretation is like in unix-matching, 
claus
parents: 343
diff changeset
  2594
	     NOT the ST-80 meaning."
328
claus
parents: 327
diff changeset
  2595
claus
parents: 327
diff changeset
  2596
    ^ self match:aString from:1 to:aString size ignoreCase:false
claus
parents: 327
diff changeset
  2597
claus
parents: 327
diff changeset
  2598
    "
claus
parents: 327
diff changeset
  2599
     '*ute*' match:'computer' 
claus
parents: 327
diff changeset
  2600
     '*uter' match:'computer' 
claus
parents: 327
diff changeset
  2601
     'uter*' match:'computer' 
claus
parents: 327
diff changeset
  2602
     '*ute*' match:'' 
claus
parents: 327
diff changeset
  2603
     '[abcd]*' match:'computer' 
claus
parents: 327
diff changeset
  2604
     '[abcd]*' match:'komputer' 
claus
parents: 327
diff changeset
  2605
     '*some*compl*ern*' match:'this is some more complicated pattern match' 
claus
parents: 327
diff changeset
  2606
     '*some*compl*ern*' match:'this is another complicated pattern match' 
claus
parents: 327
diff changeset
  2607
    "
claus
parents: 327
diff changeset
  2608
!
claus
parents: 327
diff changeset
  2609
claus
parents: 327
diff changeset
  2610
match:aString from:start to:stop ignoreCase:ignoreCase
claus
parents: 327
diff changeset
  2611
    "return true if part of aString matches myself, 
claus
parents: 327
diff changeset
  2612
     where self may contain meta-match 
claus
parents: 327
diff changeset
  2613
     characters $* (to match any string) or $# (to match any character)
claus
parents: 327
diff changeset
  2614
     or [...] to match a set of characters.
345
claus
parents: 343
diff changeset
  2615
     If ignoreCase is true, lower/uppercase are considered the same.
claus
parents: 343
diff changeset
  2616
     NOTICE: match-meta character interpretation is like in unix-matching, 
claus
parents: 343
diff changeset
  2617
	     NOT the ST-80 meaning."
328
claus
parents: 327
diff changeset
  2618
claus
parents: 327
diff changeset
  2619
    |matchScanArray|
claus
parents: 327
diff changeset
  2620
claus
parents: 327
diff changeset
  2621
    "
claus
parents: 327
diff changeset
  2622
     keep the matchScanArray from the most recent match -
claus
parents: 327
diff changeset
  2623
     avoids parsing the pattern over-and over if multiple searches
claus
parents: 327
diff changeset
  2624
     are done with the same pattern.
claus
parents: 327
diff changeset
  2625
    "
claus
parents: 327
diff changeset
  2626
    (PreviousMatch notNil
claus
parents: 327
diff changeset
  2627
    and:[PreviousMatch key = self]) ifTrue:[
claus
parents: 327
diff changeset
  2628
	matchScanArray := PreviousMatch value
claus
parents: 327
diff changeset
  2629
    ] ifFalse:[
claus
parents: 327
diff changeset
  2630
	matchScanArray := self class matchScanArrayFrom:self.
claus
parents: 327
diff changeset
  2631
	matchScanArray isNil ifTrue:[
356
claus
parents: 350
diff changeset
  2632
	    'CHARARRAY: invalid matchpattern:' infoPrint. self infoPrintNL.
328
claus
parents: 327
diff changeset
  2633
	    ^ false
claus
parents: 327
diff changeset
  2634
	].
claus
parents: 327
diff changeset
  2635
	PreviousMatch := self -> matchScanArray.
claus
parents: 327
diff changeset
  2636
    ].
claus
parents: 327
diff changeset
  2637
claus
parents: 327
diff changeset
  2638
    ^ self class
claus
parents: 327
diff changeset
  2639
	matchScan:matchScanArray 
claus
parents: 327
diff changeset
  2640
	from:1 to:matchScanArray size
claus
parents: 327
diff changeset
  2641
	with:aString 
claus
parents: 327
diff changeset
  2642
	from:start to:stop 
claus
parents: 327
diff changeset
  2643
	ignoreCase:ignoreCase
claus
parents: 327
diff changeset
  2644
claus
parents: 327
diff changeset
  2645
    "
claus
parents: 327
diff changeset
  2646
     '*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true 
claus
parents: 327
diff changeset
  2647
     '*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true  
claus
parents: 327
diff changeset
  2648
    "
359
claus
parents: 357
diff changeset
  2649
!
claus
parents: 357
diff changeset
  2650
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2651
match:aString ignoreCase:ignoreCase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2652
    "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
  2653
     characters $* (to match any string) or $# (to match any character)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2654
     or [...] to match a set of characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2655
     If ignoreCase is true, lower/uppercase are considered the same.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2656
     NOTICE: match-meta character interpretation is like in unix-matching, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2657
	     NOT the ST-80 meaning."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2658
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2659
    ^ self match:aString from:1 to:aString size ignoreCase:ignoreCase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2660
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2661
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2662
     '*ute*' match:'COMPUTER' ignoreCase:true  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2663
     '*uter' match:'COMPUTER' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2664
     '[abcd]*' match:'computer' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2665
     '[abcd]*' match:'Computer' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2666
     '[a-k]*' match:'komputer' ignoreCase:false   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2667
     '[a-k]*' match:'zomputer' ignoreCase:false    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2668
     '[a-k]*' match:'Komputer' ignoreCase:false    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2669
     '[a-k]*' match:'Komputer' ignoreCase:true     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2670
     '*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
  2671
     '*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
  2672
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2673
     Time millisecondsToRun:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2674
	Symbol allInstancesDo:[:sym |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2675
	    '[ab]*' match:sym ignoreCase:false
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2676
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2677
     ]. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2678
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2679
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2680
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2681
!CharacterArray methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2682
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2683
article
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2684
    "return an article string for the receiver."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2685
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2686
    |firstChar|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2687
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2688
    firstChar := (self at:1) asLowercase. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2689
    (firstChar isVowel or:[firstChar == $x]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2690
	firstChar ~~ $u ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2691
	     ^ 'an'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2692
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2693
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2694
    ^ 'a'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2695
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2696
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2697
displayString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2698
    "return a string to display the receiver - use storeString to have
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2699
     quotes around."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2700
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2701
    ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2702
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2703
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2704
printOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2705
    "print the receiver on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2706
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2707
    aStream nextPutAll:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2708
!
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
printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2711
    "return a string for printing - thats myself"
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
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2714
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2715
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2716
!CharacterArray methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2717
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2718
encoding
1241
431675180b54 commentary
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  2719
    "return the strings encoding, a symbol.
431675180b54 commentary
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  2720
     Here, by default, we assume iso8859 encoding.
431675180b54 commentary
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  2721
     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
  2722
19fd2f72269f keep track of encoding of 16bit strings
Claus Gittinger <cg@exept.de>
parents: 1008
diff changeset
  2723
    ^ #is8859
997
6c7f1815ed02 more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents: 991
diff changeset
  2724
1241
431675180b54 commentary
Claus Gittinger <cg@exept.de>
parents: 1235
diff changeset
  2725
    "Modified: 20.4.1996 / 23:14:18 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2726
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2727
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2728
isString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2729
    "return true, if the receiver is some kind of string;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2730
     true is returned here - redefinition of Object>>isString."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2731
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2732
    ^ true
1235
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2733
!
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2734
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2735
leftIndent
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2736
    "if the receiver starts with spaces, return the number of spaces
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2737
     at the left - otherwise, return 0.
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2738
     If the receiver consists of spaces only, return the receivers size."
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2739
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2740
    |index "{Class: SmallInteger }"
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2741
     end   "{Class: SmallInteger }"|
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2742
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2743
    index := 1.
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2744
    end := self size.
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2745
    [index <= end] whileTrue:[
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2746
        (self at:index) isSeparator ifFalse:[^ index - 1].
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2747
        index := index + 1
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2748
    ].
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2749
    ^ end
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2750
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2751
    "
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2752
     '    hello' leftIndent 
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2753
     'foo      ' leftIndent 
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2754
     '         ' leftIndent 
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2755
    "
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2756
2186eb8a2846 added #leftIndent
Claus Gittinger <cg@exept.de>
parents: 1204
diff changeset
  2757
    "Modified: 20.4.1996 / 19:28:43 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2758
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2759
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2760
!CharacterArray methodsFor:'special string converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2761
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2762
chopTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2763
    "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
  2764
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2765
     in the middle have been removed for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2766
     of maxLen."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2767
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2768
    |sz n1 n2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2769
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2770
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2771
	n1 := n2 := maxLen // 2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2772
	maxLen odd ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2773
	    n2 := n1 + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2774
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2775
	^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2776
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2777
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2778
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2779
     '12345678901234'   chopTo:15            
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2780
     '123456789012345'  chopTo:15         
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2781
     '1234567890123456' chopTo:15      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2782
     'aShortString' chopTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2783
     'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2784
    "
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2787
contractAtBeginningTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2788
    "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
  2789
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2790
     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
  2791
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2792
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2793
    |sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2794
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2795
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2796
	^ '...' , (self copyFrom:(sz - (maxLen - 4))) 
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2799
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2800
     '12345678901234' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2801
     '123456789012345' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2802
     '1234567890123456' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2803
     'aShortString' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2804
     'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2805
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2806
!
359
claus
parents: 357
diff changeset
  2807
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2808
contractAtEndTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2809
    "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
  2810
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2811
     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
  2812
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2813
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2814
    |sz|
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
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2817
	^ self copyReplaceFrom:maxLen - 3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2818
			    with:'...'
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2821
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2822
     '12345678901234' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2823
     '123456789012345' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2824
     '1234567890123456' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2825
     'aShortString' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2826
     'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2827
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2828
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2829
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2830
contractTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2831
    "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
  2832
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2833
     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
  2834
     of maxLen. Can be used to abbreviate long entries in tables."
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
    |sz "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2837
     halfSize "{ SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2838
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2839
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2840
	halfSize := maxLen // 2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2841
	^ self copyReplaceFrom:halfSize - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2842
			    to:sz - maxLen + halfSize + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2843
			    with:'...'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2844
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2845
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2846
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2847
     '12345678901234' contractTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2848
     '123456789012345' contractTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2849
     '1234567890123456' contractTo:15        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2850
     'aShortString' contractTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2851
     'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2852
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2853
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2854
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2855
expandPlaceholdersWith:argArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2856
    "return a copy of the receiver, where all %i escapes are
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2857
     replaced by corresponding arguments from the argArray.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2858
     I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2859
     in the new string 'hello world; how is this'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2860
     To get a '%' character, use a '%%'-escape.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2861
     See also bindWith:... for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2862
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2863
    |expandedString next 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2864
     idx   "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2865
     start "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2866
     stop  "{ SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2867
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2868
    expandedString := self species new:0.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2869
    stop := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2870
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2871
    [start <= stop] whileTrue:[
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2872
        idx := self indexOf:$% startingAt:start.
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2873
        idx == 0 ifTrue:[
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2874
            ^ expandedString , (self copyFrom:start to:stop)
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2875
        ].
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2876
        "found a %"
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2877
        expandedString := expandedString , (self copyFrom:start to:(idx - 1)).
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2878
        next := self at:(idx + 1).
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2879
        (next == $%) ifTrue:[
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2880
            expandedString := expandedString , '%'
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2881
        ] ifFalse:[
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2882
            expandedString := expandedString , (argArray at:(next digitValue)) printString
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2883
        ].
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2884
        start := idx + 2
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2885
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2886
    ^  expandedString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2887
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2888
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2889
     'hello %1' expandPlaceholdersWith:#('world') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2890
     'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2891
     'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2892
    "
1026
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2893
455c9f609f4d care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents: 1025
diff changeset
  2894
    "Modified: 26.2.1996 / 20:29:24 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2895
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2896
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2897
withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2898
    "return a new string consisting of receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2899
     with all \-characters replaced by cr-characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2900
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2901
    ^ self copy replaceAll:$\ by:(Character cr)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2902
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2903
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2904
     'hello\world' withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2905
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2906
!
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
withEscapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2909
    "return a new string consisting of receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2910
     with all \X-character escapes replaced by corresponding-characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2911
     (similar to the way C-language Strings are converted).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2912
     The following escapes are supported:
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2913
        \r      return character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2914
        \n      newline character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2915
        \b      backspace character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2916
        \f      formfeed character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2917
        \t      tab character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2918
        \e      escape character
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2919
        \\      the \ character itself
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2920
        \nnn    three digit octal number defining the characters ascii value
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2921
        \other  other
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2922
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2923
     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
  2924
     string constants is not affected by this method.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2925
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2926
     Although easily implementable, this is NOT done automatically
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2927
     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
  2928
     However, the compiler may detect sends ot #withEscapes to string literals
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2929
     and place a modified string constant into the binary/byte-code.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2930
     Therefore, no runtime penalty will be payed for using these escapes.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2931
     (not in pre 2.11 versions)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2932
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2933
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2934
    |sz      "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2935
     newSize "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2936
     srcIdx  "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2937
     dstIdx  "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2938
     val     "{ SmallInteger }"
986
c3a9f590146d removed unused locals
Claus Gittinger <cg@exept.de>
parents: 915
diff changeset
  2939
     newString next| 
359
claus
parents: 357
diff changeset
  2940
claus
parents: 357
diff changeset
  2941
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2942
     first, count the number of escapes, to allow preallocation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2943
     of the new string ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2944
     (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
  2945
      times in a WriteStream)
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
    sz := newSize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2948
    srcIdx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2949
    [(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2950
        srcIdx == sz ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2951
            newSize := newSize - 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2952
            srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2953
            next := self at:srcIdx.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2954
            next == $0 ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2955
                [(self at:srcIdx) isDigit] whileTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2956
                    newSize := newSize - 1. srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2957
                ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2958
            ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2959
        ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2960
        srcIdx := srcIdx + 1.
608
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2963
    newSize == sz ifTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2964
        ^ self
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2965
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2966
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2967
    newString := self species new:newSize.
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
     copy over, replace escapes
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
    srcIdx := dstIdx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2972
    [srcIdx <= sz] whileTrue:[
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2973
        next := self at:srcIdx.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2974
        srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2975
        next == $\ ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2976
            srcIdx <= sz ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2977
                next := self at:srcIdx.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2978
                srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2979
                next == $r ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2980
                    next := Character return
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2981
                ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2982
                    next == $n ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2983
                        next := Character nl
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2984
                    ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2985
                        next == $b ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2986
                            next := Character backspace
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2987
                        ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2988
                            next == $f ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2989
                                next := Character newPage
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2990
                            ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2991
                                next == $t ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2992
                                    next := Character tab
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2993
                                ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2994
                                    next == $e ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2995
                                        next := Character esc
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2996
                                    ] ifFalse:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2997
                                        next == $0 ifTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2998
                                            val := 0.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  2999
                                            [next isDigit] whileTrue:[
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3000
                                                val := val * 8 + next digitValue.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3001
                                                next := self at:srcIdx.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3002
                                                srcIdx := srcIdx + 1.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3003
                                            ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3004
                                            next := Character value:val.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3005
                                        ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3006
                                    ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3007
                                ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3008
                            ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3009
                        ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3010
                    ]
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3011
                ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3012
            ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3013
        ].
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3014
        newString at:dstIdx put:next.
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3015
        dstIdx := dstIdx + 1.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3016
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3017
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3018
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3019
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3020
     'hello world' withEscapes  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3021
     'hello\world' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3022
     'hello\world\' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3023
     'hello world\' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3024
     'hello\tworld' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3025
     'hello\nworld\na\n\tnice\n\t\tstring' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3026
     'hello\tworld\n' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3027
     'hello\010world' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3028
     'hello\r\nworld' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3029
    "
1008
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3030
1bd95ea83cac add \e in #withEscapes
Claus Gittinger <cg@exept.de>
parents: 1006
diff changeset
  3031
    "Modified: 23.2.1996 / 23:25:43 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3032
!
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
withTabs
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3035
    "return a string consisting of the receivers characters
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3036
     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
  3037
     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
  3038
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3039
     Limitation: only the very first spaces are replaced 
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3040
		 (i.e. if the receiver contains newLine characters,
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3041
		  no tabs are inserted after those lineBreaks)"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3042
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3043
    |idx   "{ SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3044
     nTabs "{ SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3045
     newString|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3046
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3047
    idx := self findFirst:[:c | (c ~~ Character space)].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3048
    nTabs := (idx-1) // 8.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3049
    nTabs == 0 ifTrue:[^ self].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3050
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3051
    "any tabs"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3052
    newString := self class new:(self size - (nTabs * 7)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3053
    newString atAll:(1 to:nTabs) put:(Character tab).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3054
    newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3055
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3056
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3057
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3058
     '12345678901234567890' withTabs 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3059
     '       8901234567890' withTabs 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3060
     '        901234567890' withTabs  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3061
     '               67890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3062
     '                7890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3063
     '                 890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3064
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3065
!
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
withTabsExpanded
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3068
    "return a string consisting of the receivers characters,
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3069
     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
  3070
     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
  3071
     otherwise a new string is returned.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3072
     This does handle multiline strings."
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3073
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3074
    |idx "{ SmallInteger }" str|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3075
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3076
    (self includes:(Character tab)) ifFalse:[^ self].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3077
    str := WriteStream on:String new.
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
    idx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3080
    self do:[:ch |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3081
	ch == Character tab ifFalse:[
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3082
	    idx := idx + 1.
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3083
	    ch == Character cr ifTrue:[
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3084
		idx := 1
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3085
	    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3086
	    str nextPut:ch.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3087
	] ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3088
	    (idx \\ 8) to:8 do:[:ii |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3089
		str space.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3090
		idx := idx + 1
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3091
	    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3092
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3093
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3094
    ^ str contents
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3095
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3096
    "
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3097
     ('1' , Character tab asString , 'x') withTabsExpanded          
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3098
     ('12345' , Character tab asString , 'x') withTabsExpanded      
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3099
     ('123456' , Character tab asString , 'x') withTabsExpanded     
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3100
     ('1234567' , Character tab asString , 'x') withTabsExpanded   
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3101
     ('12345678' , Character tab asString , 'x') withTabsExpanded   
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3102
     ('123456789' , Character tab asString , 'x') withTabsExpanded 
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3103
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3104
     (String with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3105
	     with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3106
	     with:$1) withTabsExpanded
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3107
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3108
     (String with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3109
	     with:$1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3110
	     with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3111
	     with:$2) withTabsExpanded  
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3112
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3113
     (String with:Character tab
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3114
	     with:$1
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3115
	     with:Character cr
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3116
	     with:Character tab
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3117
	     with:$2) withTabsExpanded  
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3118
    "
735
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3119
362ce9e28d89 expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents: 678
diff changeset
  3120
    "Modified: 11.12.1995 / 15:27:50 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3121
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3122
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3123
withoutCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3124
    "return a new collection consisting of receivers elements
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3125
     with all cr-characters replaced by \-characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3126
     This is the reverse operation of withCRs."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3127
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3128
    ^ self copy replaceAll:(Character cr) by:$\
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3129
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3130
     'hello
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3131
world' withoutCRs
359
claus
parents: 357
diff changeset
  3132
    "
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
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3135
withoutLeadingSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3136
    "return a copy of myself without leading separators.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3137
     Notice: this does remove tabs, newline or any other whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3138
     Returns an empty string, if the receiver consist only of whitespace."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3139
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3140
    |index|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3141
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3142
    index := self indexOfNonSeparatorStartingAt:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3143
    index ~~ 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3144
	index == 1 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3145
	    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3146
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3147
	^ self copyFrom:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3148
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3149
    ^ ''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3150
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3151
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3152
     '    foo    ' withoutLeadingSeparators  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3153
     'foo    '     withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3154
     '    foo'     withoutLeadingSeparators  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3155
     '       '     withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3156
     'foo'         withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3157
     ('  ' , Character tab asString , ' foo   ') withoutLeadingSeparators inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3158
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3159
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3160
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3161
withoutSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3162
    "return a copy of myself without leading and trailing whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3163
     Whitespace is space, tab, newline, formfeed.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3164
     Use withoutSpaces, if you want to remove spaces only."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3165
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3166
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3167
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3168
     sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3169
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3170
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3171
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3172
    endIndex := sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3173
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3174
    [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3175
	startIndex := startIndex + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3176
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3177
    [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3178
	endIndex := endIndex - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3179
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3180
    startIndex > endIndex ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3181
	^ ''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3182
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3183
    ((startIndex == 1) and:[endIndex == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3184
	^ self
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
    ^ self copyFrom:startIndex to:endIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3187
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3188
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3189
     '    foo    ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3190
     '    foo' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3191
     'foo    ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3192
     '       ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3193
     ('  foo' , Character tab asString , '    ') withoutSeparators inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3194
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3195
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3196
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3197
withoutSpaces
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3198
    "return a copy of myself without leading and trailing spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3199
     Notice: this does NOT remove tabs, newline or any other whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3200
     Use withoutSeparators for this."
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
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3203
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3204
     sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3205
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3206
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3207
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3208
    endIndex := sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3209
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3210
    [(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3211
	startIndex := startIndex + 1
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
    [(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3214
	endIndex := endIndex - 1
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
    startIndex > endIndex ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3217
	^ ''
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
    ((startIndex == 1) and:[endIndex == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3220
	^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3221
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3222
    ^ self copyFrom:startIndex to:endIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3223
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
     '    foo    ' withoutSpaces  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3226
     'foo    '     withoutSpaces   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3227
     '    foo'     withoutSpaces  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3228
     '       '     withoutSpaces   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3229
     ('  foo' , Character tab asString , '    ') withoutSpaces inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3230
    "
915
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3231
!
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3232
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3233
withoutTrailingSeparators
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3234
    "return a copy of myself without trailing separators.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3235
     Notice: this does remove tabs, newline or any other whitespace.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3236
     Returns an empty string, if the receiver consist only of whitespace."
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3237
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3238
    |index|
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3239
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3240
    index := self size.
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3241
    [index ~~ 0] whileTrue:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3242
	(self at:index) isSeparator ifFalse:[
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3243
	    ^ self copyTo:index
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3244
	].
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3245
	index := index - 1
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3246
    ].
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3247
    ^ ''
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3248
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3249
    "
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3250
     '    foo    ' withoutTrailingSeparators  
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3251
     'foo    '     withoutTrailingSeparators   
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3252
     '    foo'     withoutTrailingSeparators  
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3253
     '       '     withoutTrailingSeparators   
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3254
     'foo'         withoutTrailingSeparators   
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3255
     ('  ' , Character tab asString , ' foo   ') withoutTrailingSeparators inspect 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3256
     ('   foo' , Character tab asString) withoutTrailingSeparators inspect 
1ac1c7e942f4 added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3257
    "
608
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
!CharacterArray methodsFor:'substring searching'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3261
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3262
findString:subString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3263
    "find a substring. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3264
     if not found, return 0."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3265
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  3266
    ^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0
608
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
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3269
     'hello world' findString:'llo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3270
     'hello world' findString:'ole'  
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
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3273
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3274
findString:subString ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3275
    "find a substring. If found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3276
     if not found, return the result of evaluating exceptionBlock."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3277
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3278
    ^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock
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
findString:subString startingAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3282
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3283
     if not found, return 0."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3284
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  3285
    ^ self indexOfSubCollection:subString startingAt:index ifAbsent:0
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3286
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3287
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3288
     'hello yello' findString:'llo' startingAt:1   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3289
     'hello yello' findString:'llo' startingAt:5   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3290
     'hello yello' findString:'llo' startingAt:15   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3291
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3292
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3293
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3294
findString:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3295
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3296
     if not found, return the result of evaluating exceptionBlock."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3297
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3298
    ^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3299
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3300
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3301
includesString:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3302
    "return true, if a substring is contained in the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3303
1145
a094d90e11bf dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  3304
    ^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3305
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3306
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3307
     'hello world' includesString:'hel' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3308
     'hello world' includesString:'rld' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3309
     'hello world' includesString:'llo'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3310
     'hello world' includesString:'LLO'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3311
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3312
!
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
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3315
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3316
     if not found, return the result of evaluating exceptionBlock.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3317
     This is a q&d hack - not very efficient"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3318
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3319
    |firstChar found
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3320
     startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3321
     subSize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3322
     mySize     "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3323
     runIdx     "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3324
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3325
    subSize := subString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3326
    subSize == 0 ifTrue:[^ index]. "empty string matches"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3327
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3328
    firstChar := subString at:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3329
    startIndex := self indexOf:firstChar startingAt:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3330
    [startIndex == 0] whileFalse:[
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3331
        runIdx := startIndex.
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3332
        found := true.
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3333
        1 to:subSize do:[:i |
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3334
            runIdx > mySize ifTrue:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3335
                found := false
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3336
            ] ifFalse:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3337
                (subString at:i) ~= (self at:runIdx) ifTrue:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3338
                    found := false
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3339
                ]
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3340
            ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3341
            runIdx := runIdx + 1
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3342
        ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3343
        found ifTrue:[
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3344
            ^ startIndex
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3345
        ].
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3346
        startIndex := self indexOf:firstChar startingAt:(startIndex + 1)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3347
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3348
    ^ exceptionBlock value
1005
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3349
4507487e0be6 more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents: 997
diff changeset
  3350
    "Modified: 23.2.1996 / 15:35:15 / cg"
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3351
!
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3352
652
Claus Gittinger <cg@exept.de>
parents: 651
diff changeset
  3353
restAfter:keyword withoutSeparators:strip
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3354
    "compare the left of the receiver with keyword,
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3355
     if it matches return the right. 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3356
     Finally, if strip is true, remove whiteSpace.
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3357
     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
  3358
	something: rest
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 735
diff changeset
  3359
     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
  3360
     begins with something. 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3361
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3362
     You may wonder why such a specialized method exists here
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3363
     - this is so common when processing mailboxes,
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3364
     rcs files, nntp/pop3 responses, that is was considered worth
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3365
     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
  3366
     times in variuos places."
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3367
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3368
    |rest|
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3369
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3370
    (self startsWith:keyword) ifTrue:[
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3371
	rest := self copyFrom:(keyword size + 1).
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3372
	strip ifTrue:[
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3373
	    rest := rest withoutSeparators
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3374
	].
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3375
	^ rest
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3376
    ].
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3377
    ^ nil
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3378
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3379
    "
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3380
     'foo: hello world' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3381
     'funny: something' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3382
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3383
     'foo:     hello world    ' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3384
     'foo:     hello world    ' restAfter:'foo:' withoutSeparators:false 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3385
    "
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3386
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  3387
    "Created: 25.11.1995 / 11:04:18 / cg"
328
claus
parents: 327
diff changeset
  3388
! !
claus
parents: 327
diff changeset
  3389
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
  3390
!CharacterArray methodsFor:'testing'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3391
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3392
countWords
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3393
    "return the number of words, which are separated by separators"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3394
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3395
    |tally "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3396
     start "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3397
     mySize "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3398
     stop ch|
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3399
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3400
    tally := 0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3401
    start := 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3402
    mySize := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3403
    [start <= mySize] whileTrue:[
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3404
	ch := self at:start.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3405
	ch isSeparator ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3406
	    start := start + 1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3407
	] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3408
	    stop := self indexOfSeparatorStartingAt:start.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3409
	    (stop == 0) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3410
		stop := mySize + 1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3411
	    ].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3412
	    tally := tally + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3413
	    start := stop
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3414
	]
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3415
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3416
    ^ tally
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3417
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3418
    "
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3419
     'hello world isnt this nice' countWords'
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  3420
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3421
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3422
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3423
isAlphaNumeric
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3424
    "return true, if the receiver is some alphanumeric word;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3425
     i.e. consists of a letter followed by letters or digits."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3426
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3427
    self size == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3428
	"mhmh what is this ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3429
	^ false
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3430
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3431
    (self at:1) isLetter ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3432
    self do:[:char |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3433
	char isLetterOrDigit ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3434
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3435
    ^ true
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3436
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3437
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3438
     'helloWorld' isAlphaNumeric  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3439
     'foo1234' isAlphaNumeric    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3440
     'f1234' isAlphaNumeric      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3441
     '1234' isAlphaNumeric       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3442
     '+' isAlphaNumeric         
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3443
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3444
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3445
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3446
isBlank
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3447
    "return true, if the receiver contains spaces only"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3448
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3449
    self do:[:char |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3450
	char ~~ Character space ifTrue:[^ false].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3451
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3452
    ^ true
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3453
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3454
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3455
levenshteinTo:aString
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3456
    "return the levenshtein distance to the argument, aString;
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3457
     this value corrensponds to the number of replacements that have to be
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3458
     made to get aString from the receiver.
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3459
     See IEEE transactions on Computers 1976 Pg 172 ff."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3460
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3461
    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3462
     in the following, we assum that ommiting a character
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3463
     is less of an error than inserting an extra character.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3464
     Therefore the different insertion (i) and deletion (d)
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3465
     values.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3466
    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3467
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3468
    ^ self levenshteinTo:aString s:4 c:1 i:2 d:6
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3469
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3470
    "
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3471
     'ocmprt' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3472
     'computer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3473
     'ocmputer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3474
     'cmputer' levenshteinTo:'computer'
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  3475
     'computer' levenshteinTo:'cmputer'
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3476
     'Computer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3477
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3478
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3479
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3480
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3481
    "parametrized levenshtein. 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3482
     return the levenshtein distance to the argument, aString;
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3483
     this value corrensponds to the number of replacements that have to be
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3484
     made to get aString from the receiver.
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3485
     The arguments are the costs for substitution, case-change, insertion and 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3486
     deletion of a character.
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3487
     See IEEE transactions on Computers 1976 Pg 172 ff"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3488
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3489
    |d  "delta matrix"
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3490
     len1 "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3491
     len2 "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3492
     dim  "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3493
     prevRow row col 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  3494
     dimPlus1 "{ Class: SmallInteger }"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3495
     min pp c1 c2|
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3496
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3497
    len1 := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3498
    len2 := aString size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3499
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3500
    "create the help-matrix"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3501
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3502
    dim := len1 max:len2.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3503
    dimPlus1 := dim + 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3504
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3505
    d := Array new:dimPlus1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3506
    1 to:dimPlus1 do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3507
	d at:i put:(Array new:dimPlus1)
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3508
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3509
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3510
    "init help-matrix"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3511
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3512
    (d at:1) at:1 put:0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3513
    row := d at:1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3514
    1 to:dim do:[:j |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3515
	row at:(j + 1) put:( (row at:j) + insrtWeight )
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3516
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3517
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3518
    1 to:dim do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3519
	 (d at:(i + 1)) at:1 put:(  ((d at:i) at:1) + deleteWeight )
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3520
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3521
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3522
    1 to:len1 do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3523
	c1 := self at:i.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3524
	1 to:len2 do:[:j |
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3525
	    c2 := aString at:j.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3526
	    (c1 == c2) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3527
		pp := 0
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3528
	    ] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3529
		(c1 asLowercase == c2 asLowercase) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3530
		    pp := caseWeight
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3531
		] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3532
		    pp := substWeight
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3533
		]
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3534
	    ].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3535
	    prevRow := d at:i.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3536
	    row := d at:(i + 1).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3537
	    col := j + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3538
	    min := (prevRow at:j) + pp.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3539
	    min := min min:( (row at:j) + insrtWeight).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3540
	    min := min min:( (prevRow at:col) + deleteWeight).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3541
	    row at:col put: min
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3542
	]
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3543
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3544
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3545
    ^ (d at:(len1 + 1)) at:(len2 + 1)
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3546
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3547
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3548
numArgs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3549
    "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
  3550
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3551
    |binopChars|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3552
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3553
    (self size > 2) ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3554
	binopChars := '|&-+=*/\<>~@,'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3555
	(self size == 1) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3556
	    ((binopChars occurrencesOf:(self at:1)) == 0) ifTrue:[^ 0].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3557
	    ^ 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3558
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3559
	((binopChars occurrencesOf:(self at:1)) == 0) ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3560
	    ((binopChars occurrencesOf:(self at:2)) == 0) ifFalse:[^ 1]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3561
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3562
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3563
    ^ self occurrencesOf:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3564
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3565
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3566
     'foo:bar:' numArgs  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3567
     #foo:bar: numArgs    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3568
     'hello' numArgs       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3569
     '+' numArgs   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3570
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3571
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3572
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3573
partsIfSelector
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3574
    "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
  3575
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3576
    |idx1 "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3577
     coll idx2 sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3578
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3579
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3580
    idx1 := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3581
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3582
    [true] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3583
	idx2 := self indexOf:$: startingAt:idx1 + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3584
	(idx2 == 0 or:[idx2 == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3585
	    coll add:(self copyFrom:idx1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3586
	    ^ coll
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3587
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3588
	coll add:(self copyFrom:idx1 to:idx2).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3589
	idx1 := idx2 + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3590
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3591
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3592
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3593
     'foo:bar:' partsIfSelector     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3594
     #foo:bar: partsIfSelector     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3595
     'hello' partsIfSelector       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3596
     '+' partsIfSelector           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3597
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3598
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  3599
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3600
spellAgainst: aString 
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3601
    "return an integer between 0 and 100 indicating how similar 
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3602
     the argument is to the receiver.  No case conversion is done.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3603
     This algorithm is much simpler (but also less exact) than the
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3604
     levenshtein distance. Experiment which is better for your
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3605
     application."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3606
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3607
    | i1     "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3608
      i2     "{ Class: SmallInteger }"
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3609
      next1  "{ Class: SmallInteger }"
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3610
      next2  "{ Class: SmallInteger }"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3611
      size1  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3612
      size2  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3613
      score  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3614
      maxLen "{ Class: SmallInteger }" |
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3615
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3616
    size1 := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3617
    size2 := aString size.
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3618
    maxLen := size1 max:size2.
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3619
    score := 0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3620
    i1 := i2 := 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3621
    [i1 <= size1 and: [i2 <= size2]] whileTrue:[
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3622
	next1 := i1 + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3623
	next2 := i2 + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3624
	(self at:i1) == (aString at:i2) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3625
	    score := score+1.             
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3626
	    i1 := next1.                    
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3627
	    i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3628
	] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3629
	    (i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3630
		i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3631
	    ] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3632
		(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3633
		    i1 := next1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3634
		] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3635
		    i1 := next1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3636
		    i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3637
		] 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3638
	    ] 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3639
	] 
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3640
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3641
1124
53f6970d9d7d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1059
diff changeset
  3642
    score == maxLen ifTrue: [^ 100].
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3643
    ^ 100 * score // maxLen
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3644
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3645
    " 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3646
     'Smalltalk' spellAgainst: 'Smalltlak' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3647
     'Smalltalk' spellAgainst: 'smalltlak' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3648
     'Smalltalk' spellAgainst: 'smalltalk' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3649
     'Smalltalk' spellAgainst: 'smalltlk'  
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3650
     'Smalltalk' spellAgainst: 'Smalltolk'   
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  3651
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3652
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  3653
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3654
!CharacterArray class methodsFor:'documentation'!
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3655
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3656
version
1250
0f628432aa93 fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents: 1241
diff changeset
  3657
    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.74 1996-04-22 13:48:18 cg Exp $'
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  3658
! !