add NewStringEmpty, use more StringEuqual and less Strcmp
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7897 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
255296362f
commit
628dc6b32b
24 changed files with 253 additions and 218 deletions
|
|
@ -455,7 +455,7 @@ DohGetVoid(DOH *obj, const DOH *name) {
|
|||
void
|
||||
DohSetInt(DOH *obj, const DOH *name, int value) {
|
||||
DOH *temp;
|
||||
temp = NewString("");
|
||||
temp = NewStringEmpty();
|
||||
Printf(temp,"%d",value);
|
||||
Setattr(obj,(DOH *) name,temp);
|
||||
}
|
||||
|
|
@ -467,7 +467,7 @@ DohSetInt(DOH *obj, const DOH *name, int value) {
|
|||
void
|
||||
DohSetDouble(DOH *obj, const DOH *name, double value) {
|
||||
DOH *temp;
|
||||
temp = NewString("");
|
||||
temp = NewStringEmpty();
|
||||
Printf(temp,"%0.17f",value);
|
||||
Setattr(obj,(DOH *) name,temp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
#define DohStringUngetc DOH_NAMESPACE(StringUngetc)
|
||||
#define DohStringAppend DOH_NAMESPACE(StringAppend)
|
||||
#define DohStringLen DOH_NAMESPACE(StringLen)
|
||||
#define DohStringChar DOH_NAMESPACE(StringChar)
|
||||
#define DohStringEqual DOH_NAMESPACE(StringEqual)
|
||||
|
||||
|
||||
|
|
@ -95,6 +96,7 @@
|
|||
#define DohIsString DOH_NAMESPACE(IsString)
|
||||
#define DohIsFile DOH_NAMESPACE(IsFile)
|
||||
#define DohNewString DOH_NAMESPACE(NewString)
|
||||
#define DohNewStringEmpty DOH_NAMESPACE(NewStringEmpty)
|
||||
#define DohNewStringWithSize DOH_NAMESPACE(NewStringWithSize)
|
||||
#define DohNewStringf DOH_NAMESPACE(NewStringf)
|
||||
#define DohStrcmp DOH_NAMESPACE(Strcmp)
|
||||
|
|
@ -255,6 +257,7 @@ extern int DohString_getc(DOH *so);
|
|||
extern int DohString_ungetc(DOH *so, int ch);
|
||||
extern void DohString_append(DOH *so, DOH *str);
|
||||
extern int DohString_len(DOH *s1);
|
||||
extern char *DohString_char(DOH *s1);
|
||||
extern int DohString_equal(DOH *s1, DOH *s2);
|
||||
|
||||
#define DohStringPutc(ch,so) DohString_putc(so, ch)
|
||||
|
|
@ -262,6 +265,7 @@ extern int DohString_equal(DOH *s1, DOH *s2);
|
|||
#define DohStringUngetc(ch,so) DohString_ungetc(so, ch)
|
||||
#define DohStringAppend(so,str) DohString_append(so, str)
|
||||
#define DohStringLen(so) DohString_len(so)
|
||||
#define DohStringChar(so) DohString_char(so)
|
||||
#define DohStringEqual(s1,s2) DohString_equal(s1,s2)
|
||||
|
||||
/* Meta-variables */
|
||||
|
|
@ -291,6 +295,7 @@ extern int DohGetmark(DOH *obj);
|
|||
* Strings.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHString *DohNewStringEmpty();
|
||||
extern DOHString *DohNewString(const DOH *c);
|
||||
extern DOHString *DohNewStringWithSize(const DOH *c, int len);
|
||||
extern DOHString *DohNewStringf(const DOH *fmt, ...);
|
||||
|
|
@ -394,6 +399,7 @@ extern void DohMemoryDebug(void);
|
|||
#define StringUngetc DohStringUngetc
|
||||
#define StringAppend DohStringAppend
|
||||
#define StringLen DohStringLen
|
||||
#define StringChar DohStringChar
|
||||
#define StringEqual DohStringEqual
|
||||
|
||||
#define Close DohClose
|
||||
|
|
@ -419,6 +425,7 @@ extern void DohMemoryDebug(void);
|
|||
#define Setmeta DohSetmeta
|
||||
#define Delmeta DohDelmeta
|
||||
#define NewString DohNewString
|
||||
#define NewStringEmpty DohNewStringEmpty
|
||||
#define NewStringWithSize DohNewStringWithSize
|
||||
#define NewStringf DohNewStringf
|
||||
#define NewHash DohNewHash
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ DohSplit(DOH *in, char ch, int nsplits) {
|
|||
}
|
||||
|
||||
while (1) {
|
||||
str = NewString("");
|
||||
str = NewStringEmpty();
|
||||
do {
|
||||
c = Getc(in);
|
||||
} while ((c != EOF) && (c == ch));
|
||||
|
|
@ -515,7 +515,7 @@ DohSplitLines(DOH *in) {
|
|||
}
|
||||
|
||||
while (c != EOF) {
|
||||
str = NewString("");
|
||||
str = NewStringEmpty();
|
||||
while ((c = Getc(in)) != '\n' && c != EOF) {
|
||||
Putc(c, str);
|
||||
}
|
||||
|
|
@ -536,7 +536,7 @@ DOH *
|
|||
DohReadline(DOH *in) {
|
||||
char c;
|
||||
int n = 0;
|
||||
DOH *s = NewString("");
|
||||
DOH *s = NewStringEmpty();
|
||||
while (1) {
|
||||
if (Read(in,&c,1) < 0) {
|
||||
if (n == 0) {
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@ Hash_str(DOH *ho) {
|
|||
static int indent = 4;
|
||||
Hash *h = (Hash *) ObjData(ho);
|
||||
|
||||
s = NewString("");
|
||||
s = NewStringEmpty();
|
||||
if (ObjGetMark(ho)) {
|
||||
Printf(s,"Hash(0x%x)",ho);
|
||||
return s;
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ List_str(DOH *lo) {
|
|||
DOH *s;
|
||||
int i;
|
||||
List *l = (List *) ObjData(lo);
|
||||
s = NewString("");
|
||||
s = NewStringEmpty();
|
||||
if (ObjGetMark(lo)) {
|
||||
Printf(s,"List(%x)", lo);
|
||||
return s;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ String_data(DOH *so) {
|
|||
return (void *) s->str;
|
||||
}
|
||||
|
||||
char *
|
||||
DohString_char(DOH *so) {
|
||||
return (char *) String_data(so);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* int String_dump() - Serialize a string onto out
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -426,7 +431,6 @@ static int
|
|||
String_seek(DOH *so, long offset, int whence)
|
||||
{
|
||||
int pos, nsp, inc;
|
||||
int prev;
|
||||
String *s = (String *) ObjData(so);
|
||||
if (whence == SEEK_SET) pos = 0;
|
||||
else if (whence == SEEK_CUR) pos = s->sp;
|
||||
|
|
@ -450,7 +454,7 @@ String_seek(DOH *so, long offset, int whence)
|
|||
register char *tc = s->str;
|
||||
register int len = s->len;
|
||||
while (sp != nsp) {
|
||||
prev = sp + inc;
|
||||
int prev = sp + inc;
|
||||
if (prev>=0 && prev<=len && tc[prev] == '\n')
|
||||
s->line += inc;
|
||||
sp+=inc;
|
||||
|
|
@ -458,7 +462,6 @@ String_seek(DOH *so, long offset, int whence)
|
|||
#else
|
||||
register int sp = s->sp;
|
||||
register char *tc = s->str;
|
||||
register int len = s->len;
|
||||
if (inc > 0) {
|
||||
while (sp != nsp) {
|
||||
if (tc[++sp] == '\n')
|
||||
|
|
@ -1008,17 +1011,19 @@ DohNewString(const DOH *so)
|
|||
int l = 0, max;
|
||||
String *str;
|
||||
char *s;
|
||||
int hashkey = -1;
|
||||
if (DohCheck(so)) {
|
||||
str = (String *) ObjData(so);
|
||||
s = String_data((String *)so);
|
||||
l = s ? str->len : 0;
|
||||
hashkey = str->hashkey;
|
||||
} else {
|
||||
s = (char *) so;
|
||||
l = s ? (int) strlen(s) : 0;
|
||||
}
|
||||
|
||||
str = (String *) DohMalloc(sizeof(String));
|
||||
str->hashkey = -1;
|
||||
str->hashkey = hashkey;
|
||||
str->sp = 0;
|
||||
str->line = 1;
|
||||
str->file = 0;
|
||||
|
|
@ -1040,6 +1045,26 @@ DohNewString(const DOH *so)
|
|||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewStringEmpty() - Create a new string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOHString *
|
||||
DohNewStringEmpty()
|
||||
{
|
||||
int max = INIT_MAXSIZE;
|
||||
String *str = (String *) DohMalloc(sizeof(String));
|
||||
str->hashkey = 0;
|
||||
str->sp = 0;
|
||||
str->line = 1;
|
||||
str->file = 0;
|
||||
str->str = (char *) DohMalloc(max);
|
||||
str->maxsize = max;
|
||||
str->str[0] = 0;
|
||||
str->len = 0;
|
||||
return DohObjMalloc(&DohStringType,str);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewStringWithSize(const char *c, int len) - Create a new string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -1092,7 +1117,7 @@ DohNewStringf(const DOH *fmt, ...)
|
|||
va_list ap;
|
||||
DOH *r;
|
||||
va_start(ap,fmt);
|
||||
r = NewString("");
|
||||
r = NewStringEmpty();
|
||||
DohvPrintf(r,Char(fmt),ap);
|
||||
va_end(ap);
|
||||
return (DOHString *) r;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue