Reimplemented Swig_string_ucase(String *s) to take into account digits in names.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8675 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Charlie Savage 2006-02-02 09:02:11 +00:00
commit 165dd09f7a

View file

@ -190,24 +190,32 @@ String *Swig_string_ccase(String *s) {
String *Swig_string_ucase(String *s) {
String *ns;
int first = 0;
int c;
int lastC = 0;
int underscore = 0;
ns = NewStringEmpty();
/* We insert a underscore when:
1. Lower case char followed by upper case char
getFoo > get_foo; getFOo > get_foo; GETFOO > getfoo
2. Number proceded by char
get2D > get_2d; get22D > get_22d; GET2D > get_2d */
Seek(s,0,SEEK_SET);
while ((c = Getc(s)) != EOF) {
if (isalpha(c)) {
if (isupper(c)) {
if (first) Putc('_',ns);
first = 0;
} else {
first = 1;
}
}
else if (c == '_') {
/* We don't want two underscores in a row */
first = 0;
}
if (isdigit(c) && isalpha(lastC))
underscore = 1;
else if (isupper(c) && isalpha(lastC) && !isupper(lastC))
underscore = 1;
lastC = c;
if (underscore) {
Putc('_',ns);
underscore = 0;
}
Putc(tolower(c),ns);
}
return ns;