Fix String_delslice() to update s->sp and s->lines correctly.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9345 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0d1a7f5652
commit
af038c7126
2 changed files with 15 additions and 9 deletions
|
|
@ -263,6 +263,7 @@ extern void DohString_append(DOH *so, DOH *str);
|
||||||
extern int DohString_len(DOH *s1);
|
extern int DohString_len(DOH *s1);
|
||||||
extern char *DohString_char(DOH *s1);
|
extern char *DohString_char(DOH *s1);
|
||||||
extern int DohString_equal(DOH *s1, DOH *s2);
|
extern int DohString_equal(DOH *s1, DOH *s2);
|
||||||
|
extern int DohString_delslice(DOH *so, int sindex, int eindex);
|
||||||
|
|
||||||
#define DohStringPutc(ch,so) DohString_putc(so, ch)
|
#define DohStringPutc(ch,so) DohString_putc(so, ch)
|
||||||
#define DohStringGetc(so) DohString_getc(so)
|
#define DohStringGetc(so) DohString_getc(so)
|
||||||
|
|
|
||||||
|
|
@ -347,23 +347,28 @@ static int
|
||||||
String_delslice(DOH *so, int sindex, int eindex) {
|
String_delslice(DOH *so, int sindex, int eindex) {
|
||||||
String *s = (String *) ObjData(so);
|
String *s = (String *) ObjData(so);
|
||||||
int size;
|
int size;
|
||||||
|
if (s->len == 0) return 0;
|
||||||
s->hashkey = -1;
|
s->hashkey = -1;
|
||||||
if (eindex == DOH_END) eindex = s->len;
|
if (eindex == DOH_END) eindex = s->len;
|
||||||
if (sindex == DOH_BEGIN) sindex = 0;
|
if (sindex == DOH_BEGIN) sindex = 0;
|
||||||
if (s->len == 0) return 0;
|
|
||||||
|
|
||||||
size = eindex - sindex;
|
size = eindex - sindex;
|
||||||
if (s->sp > eindex) {
|
if (s->sp > sindex) {
|
||||||
/* Adjust the file pointer and line count */
|
/* Adjust the file pointer and line count */
|
||||||
char *c = s->str + sindex;
|
int i, end;
|
||||||
int i;
|
if (s->sp > eindex) {
|
||||||
for (i = 0; i < size; i++) {
|
end = eindex;
|
||||||
if (*c == '\n') s->line--;
|
s->sp -= size;
|
||||||
|
} else {
|
||||||
|
end = s->sp;
|
||||||
|
s->sp = sindex;
|
||||||
|
}
|
||||||
|
for (i = sindex; i < end; i++) {
|
||||||
|
if (s->str[i] == '\n') s->line--;
|
||||||
}
|
}
|
||||||
s->sp -= size;
|
|
||||||
assert(s->sp >= 0);
|
assert(s->sp >= 0);
|
||||||
}
|
}
|
||||||
memmove(s->str+sindex,s->str+eindex, ((s->len-size) - sindex));
|
memmove(s->str+sindex, s->str+eindex, s->len-eindex);
|
||||||
s->len -= size;
|
s->len -= size;
|
||||||
s->str[s->len] = 0;
|
s->str[s->len] = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue