Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are a very redundant person, that's what kind of person you are.


comp / comp.lang.lisp / Re: cl-ppcre question

SubjectAuthor
o Re: cl-ppcre questionB. Pym

1
Subject: Re: cl-ppcre question
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 7 Aug 2024 19:21 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: cl-ppcre question
Date: Wed, 7 Aug 2024 19:21:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <v90hg5$3a46d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 07 Aug 2024 21:21:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7094501a9f209988b45d39573ac7d250";
logging-data="3477709"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JYRiq1Ti4HHnU6/HJ0OrN"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:lVvPjxPHvdeC1LjMYyOrUoIh0LU=
View all headers

Madhu wrote:

> | I would like to parse color names in X11's rgb.txt. They look like this:
> |
> | 119 136 153 light slate gray
> | 119 136 153 LightSlateGray
> |
> | When parsing each line, I would like to get the color triplet, and the
> | name. I tried it like this:
> |
> | (let ((color-scanner
> | (cl-ppcre:create-scanner
> | "^ +([0-9]{0,2}) +([0-9]{0,2}) +([0-9]{0,2}) +([ a-zA-Z0-9]+)")))
> | (cl-ppcre:scan-to-strings color-scanner " 1 2 3 foo bar baz "))
> |
> | This gives #("1" "2" "3" "foo bar baz ") for the substrings. How can
> | I get rid of the trailing spaces?
>
> Use the right tool for the job :)
>
> (defun parse-rgb-line (string &key (start 0) end)
> (multiple-value-bind (r endr)
> (parse-integer string :start start :end end :junk-allowed t)
> (multiple-value-bind (g endg)
> (parse-integer string :start (1+ endr) :end end :junk-allowed t)
> (multiple-value-bind (b endb)
> (parse-integer string :start (1+ endg) :end end :junk-allowed t)
> (let ((name-startpos
> (position-if-not (lambda (c) (case c ((#\Tab #\Space) t)))
> string :start (1+ endb))))
> (values (format nil "#~2,'0X~2,'0X~2,'0X" r g b)
> (subseq string name-startpos end)))))))

newLISP

(define (parse-rgb-line s)
(find-all
{(\d+)|(\S.*)}
(trim s)
(or (int $0) $0)))

(parse-rgb-line "119 136 153 light slate gray ")

(119 136 153 "light slate gray")

1

rocksolid light 0.9.8
clearnet tor