add direct methods StringLen and HashGetAttr

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7890 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-11-28 02:36:26 +00:00
commit ba9b1ec591
3 changed files with 49 additions and 12 deletions

View file

@ -71,6 +71,7 @@
#define DohStringGetc DOH_NAMESPACE(StringGetc) #define DohStringGetc DOH_NAMESPACE(StringGetc)
#define DohStringUngetc DOH_NAMESPACE(StringUngetc) #define DohStringUngetc DOH_NAMESPACE(StringUngetc)
#define DohStringAppend DOH_NAMESPACE(StringAppend) #define DohStringAppend DOH_NAMESPACE(StringAppend)
#define DohStringLen DOH_NAMESPACE(StringLen)
#define DohStringEqual DOH_NAMESPACE(StringEqual) #define DohStringEqual DOH_NAMESPACE(StringEqual)
@ -108,6 +109,7 @@
#define DohCopyto DOH_NAMESPACE(Copyto) #define DohCopyto DOH_NAMESPACE(Copyto)
#define DohNewList DOH_NAMESPACE(NewList) #define DohNewList DOH_NAMESPACE(NewList)
#define DohNewHash DOH_NAMESPACE(NewHash) #define DohNewHash DOH_NAMESPACE(NewHash)
#define DohHashGetAttr DOH_NAMESPACE(HashGetAttr)
#define DohHashCheckAttr DOH_NAMESPACE(HashCheckAttr) #define DohHashCheckAttr DOH_NAMESPACE(HashCheckAttr)
#define DohNewVoid DOH_NAMESPACE(NewVoid) #define DohNewVoid DOH_NAMESPACE(NewVoid)
#define DohSplit DOH_NAMESPACE(Split) #define DohSplit DOH_NAMESPACE(Split)
@ -252,12 +254,14 @@ extern int DohString_putc(DOH *so, int ch);
extern int DohString_getc(DOH *so); extern int DohString_getc(DOH *so);
extern int DohString_ungetc(DOH *so, int ch); extern int DohString_ungetc(DOH *so, int ch);
extern void DohString_append(DOH *so, DOH *str); extern void DohString_append(DOH *so, DOH *str);
extern int DohString_len(DOH *s1);
extern int DohString_equal(DOH *s1, DOH *s2); extern int DohString_equal(DOH *s1, DOH *s2);
#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)
#define DohStringUngetc(ch,so) DohString_ungetc(so, ch) #define DohStringUngetc(ch,so) DohString_ungetc(so, ch)
#define DohStringAppend(so,str) DohString_append(so, str) #define DohStringAppend(so,str) DohString_append(so, str)
#define DohStringLen(so) DohString_len(so)
#define DohStringEqual(s1,s2) DohString_equal(s1,s2) #define DohStringEqual(s1,s2) DohString_equal(s1,s2)
/* Meta-variables */ /* Meta-variables */
@ -332,6 +336,7 @@ extern void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *));
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
extern DOHHash *DohNewHash(); extern DOHHash *DohNewHash();
extern DOH *DohHashGetAttr(DOH *hash, DOH *key);
extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value); extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value);
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -388,6 +393,7 @@ extern void DohMemoryDebug(void);
#define StringGetc DohStringGetc #define StringGetc DohStringGetc
#define StringUngetc DohStringUngetc #define StringUngetc DohStringUngetc
#define StringAppend DohStringAppend #define StringAppend DohStringAppend
#define StringLen DohStringLen
#define StringEqual DohStringEqual #define StringEqual DohStringEqual
#define Close DohClose #define Close DohClose
@ -416,6 +422,7 @@ extern void DohMemoryDebug(void);
#define NewStringWithSize DohNewStringWithSize #define NewStringWithSize DohNewStringWithSize
#define NewStringf DohNewStringf #define NewStringf DohNewStringf
#define NewHash DohNewHash #define NewHash DohNewHash
#define HashGetAttr DohHashGetAttr
#define HashCheckAttr DohHashCheckAttr #define HashCheckAttr DohHashCheckAttr
#define NewList DohNewList #define NewList DohNewList
#define NewFile DohNewFile #define NewFile DohNewFile

View file

@ -276,11 +276,19 @@ Hash_getattr(DOH *h, DOH *k) {
return obj; return obj;
} }
DOH *
DohHashGetAttr(DOH *h, DOH *k) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
_Hash_getattr(ho, k, obj);
return obj;
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Hash_checkattr() * HashCheckAttr()
* *
* Get an attribute from the hash table. Returns 0 if it doesn't exist. * Check an attribute from the hash table.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int

View file

@ -65,7 +65,7 @@ CopyString(DOH *so) {
String *str; String *str;
String *s = (String *) ObjData(so); String *s = (String *) ObjData(so);
str = (String *) DohMalloc(sizeof(String)); str = (String *) DohMalloc(sizeof(String));
str->hashkey = -1; str->hashkey = s->hashkey;
str->sp = s->sp; str->sp = s->sp;
str->line = s->line; str->line = s->line;
str->file = s->file; str->file = s->file;
@ -87,18 +87,16 @@ CopyString(DOH *so) {
static void static void
DelString(DOH *so) { DelString(DOH *so) {
String *s = (String *) ObjData(so); String *s = (String *) ObjData(so);
s->hashkey = -1;
DohFree(s->str); DohFree(s->str);
s->str = 0;
DohFree(s); DohFree(s);
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* String_len() - Length of a string * DohString_len() - Length of a string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
static int int
String_len(DOH *so) { DohString_len(DOH *so) {
String *s = (String *) ObjData(so); String *s = (String *) ObjData(so);
return s->len; return s->len;
} }
@ -237,6 +235,7 @@ DohString_append(DOH *so, DOH *str) {
s->len += l; s->len += l;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* void String_clear() - Clear a string * void String_clear() - Clear a string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -269,17 +268,23 @@ String_insert(DOH *so, int pos, DOH *str)
return 0; return 0;
} }
s = (String *) ObjData(so); s = (String *) ObjData(so);
s->hashkey = -1; s->hashkey = -1;
data = (char *) DohData(str); if (DohCheck(str)) {
String *ss = (String *) ObjData(str);
data = String_data(str);
len = ss->len;
} else {
data = (char *) (str);
len = (int) strlen(data);
}
nstr = s->str; nstr = s->str;
if (pos < 0) pos = 0; if (pos < 0) pos = 0;
else if (pos > s->len) pos = s->len; else if (pos > s->len) pos = s->len;
/* See if there is room to insert the new data */ /* See if there is room to insert the new data */
len = Len(str);
while (s->maxsize <= s->len+len) { while (s->maxsize <= s->len+len) {
s->str = (char *) DohRealloc(s->str,2*s->maxsize); s->str = (char *) DohRealloc(s->str,2*s->maxsize);
assert(s->str); assert(s->str);
@ -440,6 +445,7 @@ String_seek(DOH *so, long offset, int whence)
inc = (nsp > s->sp) ? 1 : -1; inc = (nsp > s->sp) ? 1 : -1;
{ {
#if 0
register int sp = s->sp; register int sp = s->sp;
register char *tc = s->str; register char *tc = s->str;
register int len = s->len; register int len = s->len;
@ -449,6 +455,22 @@ String_seek(DOH *so, long offset, int whence)
s->line += inc; s->line += inc;
sp+=inc; sp+=inc;
} }
#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')
++s->line;
}
} else {
while (sp != nsp) {
if (tc[--sp] == '\n')
--s->line;
}
}
#endif
s->sp = sp; s->sp = sp;
} }
assert (s->sp >= 0); assert (s->sp >= 0);
@ -955,7 +977,7 @@ DohObjInfo DohStringType = {
String_str, /* doh_str */ String_str, /* doh_str */
String_data, /* doh_data */ String_data, /* doh_data */
String_dump, /* doh_dump */ String_dump, /* doh_dump */
String_len, /* doh_len */ DohString_len, /* doh_len */
String_hash, /* doh_hash */ String_hash, /* doh_hash */
String_cmp, /* doh_cmp */ String_cmp, /* doh_cmp */
DohString_equal, /* doh_equal */ DohString_equal, /* doh_equal */