Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: Reverse a string (with xchars) Date: Sun, 21 Feb 2016 12:56:06 -0800 Organization: A noiseless patient Spider Lines: 12 Message-ID: <87mvqt4wbd.fsf@jester.gateway.pace.com> References: <2016Feb19.100032@mips.complang.tuwien.ac.at> <874md16d46.fsf@jester.gateway.pace.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="3c7a0b0f75f6c95b248ff930d17c36e7"; logging-data="12066"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188y+weF7tbY3jug+ZvRGG6" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:uey1Dtj/gztTS8cuaK+k+TDvZ6A= sha1:WmJ+a57NkUZ/8CmS8jUJILPmh/k= Xref: csiph.com comp.lang.forth:45661 Chris Curl writes: > each "char" on the aux stack would have the number of bytes needed, > followed by the actual bytes. 'A' would be (65 00 02 <-- TOS). a coded > char would look like this: (30 03 65 00 04) or whatever. Actually you don't need that overhead. You can just build up an array in forward order, but reverse the encoded bytes for each character. So if the encoding is (30 03 64 00) then you'd write (00 64 03 30). After doing this with all the chars, you'd scan the array backwards, parsing the encodings from the reversed stream. In fact you can do this in place, with no auxiliary storage other than a few bytes to read a single encoding and reverse it.