[Top][All Lists]

[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:


For generating this, I use the format-spec function from Gnus which
groks percent-escapes.  So I have a format string like so:


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,

Another filename format is


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 "/address@hidden:/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 "/address@hidden:/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?

A large number of young women don't trust men with beards.  (BFBS Radio)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]