From 6de4c96f1f6c7704b9b4395f17b11b8f9e553204 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Wed, 30 Aug 2000 20:23:58 +0000 Subject: [PATCH] Added Swig_string_mangle() function git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@734 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Swig/misc.c | 15 +++++++++++++++ Source/Swig/swig.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 034f221ae..4572c856a 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -131,3 +131,18 @@ String *Swig_string_escape(String *s) { return ns; } +/* ----------------------------------------------------------------------------- + * Swig_string_mangle() + * + * Take a string and mangle it by stripping all non-valid C identifier characters + * ----------------------------------------------------------------------------- */ + +String *Swig_string_mangle(String *s) { + String *t = Copy(s); + char *c = Char(t); + while (*c) { + if (!isalnum(*c)) *c = '_'; + c++; + } + return t; +} diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 587ff060a..cf52f1220 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -278,6 +278,7 @@ extern char *Swig_copy_string(const char *c); extern void Swig_banner(File *f); extern DOH *Swig_temp_result(DOH *x); extern String *Swig_string_escape(String *s); +extern String *Swig_string_mangle(String *s); /* --- C Wrappers --- */ extern String *Swig_clocal(SwigType *t, String_or_char *name, String_or_char *value);