SWI-Prolog / packages-semweb

The SWI-Prolog RDF store
29 stars 15 forks source link

Make after_char/3 public #45

Closed wouterbeek closed 8 years ago

wouterbeek commented 8 years ago

Module semweb/rdfs contains a very useful predicate after_char/3 (included below) that is not Semweb- or even IRI-specific. Can we make this a public predicate under the name atom_after_char/3? What would be the best module to put this in? There is currently no module for non-builtin atom manipulation predicates.

after_char(Atom, Char, Rest) :-
  State = last(-),
  (   sub_atom(Atom, _, _, L, Char),
      nb_setarg(1, State, L),
      fail
  ;   arg(1, State, L),
      L \== (-)
  ),
  sub_atom(Atom, _, L, 0, Rest).
JanWielemaker commented 8 years ago

I don't think this is the right primitive. If we go this way we'll end up with zillions of atom operations. I think the missing bit is a fast low-level regex implementation that can do the above easily and possibly a reverse version of sub_atom/5, i.e., one that searches backward instead of forward.

For now, simply copy this to your application ...