On Thu, 09 Dec 2010 02:14:52 -0500, Maurizio Gennaro Cataldo <[email protected]> wrote:

I really do not figure out how to implement a sorting task which involves
items
inside a line of text.
I know that BBEdit is able to sort lines but what I need is something
different.
The task is quite simple, let's say we have a line of text containing comma
separated items, something like:

*orange, **apple, pear, 1banana, 2apricot, bombay *

and after having selected the whole line I would like to push a combination
of keys
(something like cmd+O) or select a script and obtain something like:

*apple, 2apricot, 1banana, bombay, orange, pear*

In other words I would like to alphabetically order the comma separated
items
inside the line disregarding any optional number that could appear as first
characters
at the beginning of some items.

Any suggestion will be really appreciated.

I would do this by creating a little script to parse the line for you. Here's one that I would use in Chez Scheme, but any other programming language could probably do the job adequately.

#! /usr/bin/env scheme-script
(import (chezscheme) (srfi :13) (srfi :14))

(printf "~{~a~^, ~}~n"
  (list-sort
    (lambda (a b)
      (define (trim s) (string-trim-both s char-set:digit))
      (string<? (trim a) (trim b)))
    (string-tokenize (get-line (current-input-port))
      (char-set-complement
        (char-set-union char-set:whitespace
          (char-set #\,))))))

Good luck!

        Aaron W. Hsu

--
Programming is just another word for the lost art of thinking.

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to