From 1038b8eeb532b0522b8002c806ad9175a16cb234 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 28 Sep 2005 10:47:17 -0700 Subject: [PATCH] Implement atomSplit. darcs-hash:20050928174717-4cc09-e4d0f9817b49c6f73ebeee783b536aead8ad19bd.gz --- atom.c | 21 +++++++++++++++++++++ atom.h | 1 + 2 files changed, 22 insertions(+) diff --git a/atom.c b/atom.c index 48353c6..acb74e6 100644 --- a/atom.c +++ b/atom.c @@ -102,6 +102,27 @@ atomCat(AtomPtr atom, const char *string) return newAtom; } +int +atomSplit(AtomPtr atom, char c, AtomPtr *return1, AtomPtr *return2) +{ + char *p; + AtomPtr atom1, atom2; + p = memchr(atom->string, c, atom->length); + if(p == NULL) + return 0; + atom1 = internAtomN(atom->string, p - atom->string); + if(atom1 == NULL) + return -ENOMEM; + atom2 = internAtomN(p + 1, atom->length - (p + 1 - atom->string)); + if(atom2 == NULL) { + releaseAtom(atom1); + return -ENOMEM; + } + *return1 = atom1; + *return2 = atom2; + return 1; +} + AtomPtr internAtomLowerN(const char *string, int n) { diff --git a/atom.h b/atom.h index bab47ac..74853f9 100644 --- a/atom.h +++ b/atom.h @@ -42,6 +42,7 @@ AtomPtr internAtom(const char *string); AtomPtr internAtomN(const char *string, int n); AtomPtr internAtomLowerN(const char *string, int n); AtomPtr atomCat(AtomPtr atom, const char *string); +int atomSplit(AtomPtr atom, char c, AtomPtr *return1, AtomPtr *return2); AtomPtr retainAtom(AtomPtr atom); void releaseAtom(AtomPtr atom); AtomPtr internAtomError(int e, const char *f, ...) -- 2.11.4.GIT