You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 2000/01/01 15:10:27 UTC

ANNOUNCE: Str 0.9.0

On my (very long) path to a new forthcoming project, since over one year
now I'm working on the base libraries and tools for it. On my path there
were 1999 the MM (Shared Memory Library), GNU Shtool (Portable Shell
Tool), GNU Pth (Portable Threads) and various small (still unreleased)
workoffs of numerious packages (ev, Sfio, PCRE, etc.). Now the first cut
for one more of these required base libraries is available:

   Str -- http://www.engelschall.com/sw/str/

   This library is a generic string library written in ANSI C which
   provides functions for handling, matching, parsing, searching and
   formatting of C strings. So it can be considered as a superset
   of POSIX string(3), but its main intention is to provide a more
   convinient and compact API plus a more generalized functionality.

This time I was able to recycle more old code than before (e.g. parts of
our ap_snprintf.c, an old strqtok, the PCRE library, etc), so it took me
just two months to write the missing parts and create the package. This
time it is released under a very less restrictive Open Source license
(MIT-style), because the intentions of this package are different
than for instance the intentions behind GNU Pth. So the (L)GPL-haters
under us this time certainly should have no reason to complain ;) The
library API certainly will need some more polishing and testing, but
the package is already quite complete (at least it already provides the
functionality I always need).

For those who're interested, here is a short example which shows one of
its features (which I wanted for years to allow me to think Perl and
write C):

  # in Perl I often write:
  my $var = "foo:bar";
  my ($v1, $v2);
  ...
  if (($v1, $v2) = ($var =~ m/^(.+?):(.+)$/")) {
      # now we have: 
      # $v1 = "foo", $v2 = "bar";
      ...
  }
  ...

  /* with Str I now can write: */
  char *var = "foo:bar";
  char *cp, *v1, *v2;
  ...
  if (str_parse(var, "m/^(.+?):(.+)$/b", &cp, &v1, &v2)) {
      /* now we have:
         cp = "foo\0bar\0" and v1 and v2 pointing
         into it, i.e., v1 = "foo", v2 = "bar" */
      ...
      free(cp);
  }
  ...

Or some other stuff I usually do:

  # Perl:
  my $var = "foo:bar";
  my $subst = "quux";
  my $new;
  ...
  ($new = $var) =~ s/^(.+?):(.+)$/$1-${subst}-$2/;
  # now we have: $var = "foo:bar", $new = "foo:quux:bar"
  ...

  /* Str: */
  char *var = "foo:bar";
  char *subst = "quux";
  char *new;
  str_parse(var, "s/^(.+?):(.+)$/$1-%s-$2/", &new, subst);
  ...
  /* now we have: var = "foo:bar", new = "foo:quux:bar" */
  ...
  free(new);

And the performance freaks shouldn't worry too much: the m/.../ and
s/.../ strings can be compiled by PCRE internally and the resulting DFAs
are globally cached by Str if one adds the ".../o" ("once") flag (as one
is used to from Perl ;)

Any type of technical feedback for this library is welcome.

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com