7 inclusion of the above copyright notice. This software may not |
7 inclusion of the above copyright notice. This software may not |
8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
|
12 |
|
13 'From Smalltalk/X, Version:3.1.9 on 30-aug-1997 at 3:02:55 pm' ! |
12 |
14 |
13 Object subclass:#Stream |
15 Object subclass:#Stream |
14 instanceVariableNames:'signalAtEnd' |
16 instanceVariableNames:'signalAtEnd' |
15 classVariableNames:'StreamErrorSignal PositionErrorSignal ReadErrorSignal |
17 classVariableNames:'StreamErrorSignal PositionErrorSignal ReadErrorSignal |
16 WriteErrorSignal EndOfStreamSignal' |
18 WriteErrorSignal EndOfStreamSignal' |
1479 " |
1481 " |
1480 |
1482 |
1481 "Modified: 17.5.1996 / 08:51:56 / cg" |
1483 "Modified: 17.5.1996 / 08:51:56 / cg" |
1482 ! |
1484 ! |
1483 |
1485 |
1484 upToAll:aCollectionOfObjects |
1486 upToAll:aCollection |
1485 "read a collection of all objects up-to a element which is contained in |
1487 "read a collection of all objects up-to a element which is contained in |
1486 aCollectionOfObjects and return these elements, but excluding the matching one. |
1488 aCollectionOfObjects and return these elements, but excluding the matching one. |
1487 The next read operation will return the element after anObject. |
1489 The next read operation will return the element after anObject. |
1488 If no such element is encountered, all elements up to the end are read |
1490 If no such element is encountered, all elements up to the end are read |
1489 and returned. |
1491 and returned. |
1490 Compare this with #throughAll: which also reads up to some object |
1492 Compare this with #throughAll: which also reads up to some object |
1491 and also positions behind it, but DOES include it in the returned |
1493 and also positions behind it, but DOES include it in the returned |
1492 value." |
1494 value." |
1493 |
1495 |
|
1496 <resource: #tobevalidated> |
|
1497 |
|
1498 |answerStream element last rslt| |
|
1499 |
|
1500 last := aCollection last. |
|
1501 answerStream := WriteStream on:(self contentsSpecies new). |
|
1502 [self atEnd] whileFalse:[ |
|
1503 element := self next. |
|
1504 answerStream nextPut:element. |
|
1505 element == last ifTrue:[ |
|
1506 ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
|
1507 self position:(self position - aCollection size). |
|
1508 ^ rslt copyWithoutLast:aCollection size |
|
1509 ] |
|
1510 ]. |
|
1511 ]. |
|
1512 ^ answerStream contents |
|
1513 |
|
1514 " |
|
1515 |s| |
|
1516 s := ReadStream on:'hello world world'. |
|
1517 Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
1518 Transcript show:'<'; show:(s upToAll:'wo'); showCR:'>'. |
|
1519 Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
1520 " |
|
1521 " |
|
1522 |s| |
|
1523 s := ReadStream on:'hello world'. |
|
1524 Transcript show:'<'; show:(s upToAll:'xx'); showCR:'>'. |
|
1525 Transcript showCR:s atEnd. |
|
1526 Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
1527 " |
|
1528 |
|
1529 "Modified: 30.8.1997 / 03:02:11 / cg" |
|
1530 ! |
|
1531 |
|
1532 upToAny:aCollectionOfObjects |
|
1533 "read a collection of all objects up-to a element which is contained in |
|
1534 aCollectionOfObjects and return these elements, but excluding the matching one. |
|
1535 The next read operation will return the element after anObject. |
|
1536 If no such element is encountered, all elements up to the end are read |
|
1537 and returned. |
|
1538 Compare this with #throughAll: which also reads up to some object |
|
1539 and also positions behind it, but DOES include it in the returned |
|
1540 value." |
|
1541 |
1494 |answerStream element| |
1542 |answerStream element| |
1495 |
1543 |
1496 answerStream := WriteStream on:(self contentsSpecies new). |
1544 answerStream := WriteStream on:(self contentsSpecies new). |
1497 [self atEnd] whileFalse:[ |
1545 [self atEnd] whileFalse:[ |
1498 element := self next. |
1546 element := self next. |