[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Parsing and unparsing of strings according to a format
From: |
Kai Großjohann |
Subject: |
Parsing and unparsing of strings according to a format |
Date: |
Thu, 05 Sep 2002 17:51:49 +0200 |
User-agent: |
Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu) |
In Tramp, I'm operating a lot on filenames. A typical filename might
look like this:
/method:user@host:/path/to/file
For generating this, I use the format-spec function from Gnus which
groks percent-escapes. So I have a format string like so:
/%m:%u@%h:%p
Of course, %m stands for the method and so on. I also have a
home-grown regular expression with parentheses to parse the structure.
Is there a library that will help me with this? So I specify the
filename syntax and the library gives me two functions, one function
that takes method, user, host, path and gives me a string, and
another function that takes a string and gives me method, user, host,
path.
Another filename format is
/[method/user@host]/path/to/file
where the square brackets are part of the filename syntax. The
library should allow me to easily specify which of the two syntaxes I
want (and allow other syntaxes, as well), and then produce a parsing
and an unparsing function.
As a final complication, some of the components of the filename are
optional. For example, the "user@" part is optional. Also, the
"method:" part is optional. And the path can be the empty string.
(In the alternate syntax, it's "method/" instead of "method:".)
So, I specify what the filename looks like and then I have a parsing
function such that
(filename-parse "/grossjoh@schulz:/tmp")
returns a structure where method=nil, user="grossjoh", host="schulz",
path="/tmp". And I have an unparsing function such that
(filename-unparse nil "grossjoh" "schulz" "/tmp")
returns "/grossjoh@schulz:/tmp".
At least for the unparsing part, it seems that something like
mode-line-format ought to do the trick. But is there a function with
the necessary functionality?
And what about parsing?
tia,
kai
--
A large number of young women don't trust men with beards. (BFBS Radio)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Parsing and unparsing of strings according to a format,
Kai Großjohann <=