String replacement enhancements to help with preprocessor fixes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4298 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3519b94187
commit
c320b09704
2 changed files with 38 additions and 1 deletions
|
|
@ -256,6 +256,8 @@ extern char *DohStrchr(const DOHString_or_char *s1, int ch);
|
|||
#define DOH_REPLACE_NOQUOTE 0x02
|
||||
#define DOH_REPLACE_ID 0x04
|
||||
#define DOH_REPLACE_FIRST 0x08
|
||||
#define DOH_REPLACE_ID_BEGIN 0x10
|
||||
#define DOH_REPLACE_ID_END 0x20
|
||||
|
||||
#define Replaceall(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ANY)
|
||||
#define Replaceid(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ID)
|
||||
|
|
|
|||
|
|
@ -496,6 +496,37 @@ match_identifier(char *base, char *s, char *token, int tokenlen)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
match_identifier_begin(char *base, char *s, char *token, int tokenlen)
|
||||
{
|
||||
while (s) {
|
||||
s = strstr(s,token);
|
||||
if (!s) return 0;
|
||||
if ((s > base) && (isalnum(*(s-1)) || (*(s-1) == '_'))) {
|
||||
s += tokenlen;
|
||||
continue;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
match_identifier_end(char *base, char *s, char *token, int tokenlen)
|
||||
{
|
||||
while (s) {
|
||||
s = strstr(s,token);
|
||||
if (!s) return 0;
|
||||
if (isalnum(*(s+tokenlen)) || (*(s+tokenlen) == '_')) {
|
||||
s += tokenlen;
|
||||
continue;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int))
|
||||
{
|
||||
|
|
@ -714,7 +745,11 @@ String_replace(DOH *stro, DOH *token, DOH *rep, int flags)
|
|||
|
||||
if (flags & DOH_REPLACE_FIRST) count = 1;
|
||||
|
||||
if (flags & DOH_REPLACE_ID) {
|
||||
if (flags & DOH_REPLACE_ID_END) {
|
||||
return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier_end);
|
||||
} else if (flags & DOH_REPLACE_ID_BEGIN) {
|
||||
return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier_begin);
|
||||
} else if (flags & DOH_REPLACE_ID) {
|
||||
return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier);
|
||||
} else {
|
||||
return replace_simple(str,Char(token), Char(rep), flags, count, match_simple);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue