diff --git a/ase/include/ase/cmn/str.h b/ase/include/ase/cmn/str.h
index 8a812792..f1cee694 100644
--- a/ase/include/ase/cmn/str.h
+++ b/ase/include/ase/cmn/str.h
@@ -1,5 +1,5 @@
/*
- * $Id: str.h 223 2008-06-26 06:44:41Z baconevi $
+ * $Id: str.h 352 2008-08-31 10:55:59Z baconevi $
*
* {License}
*/
@@ -20,21 +20,20 @@ typedef struct ase_str_t ase_str_t;
struct ase_str_t
{
+ ase_mmgr_t* mmgr;
ase_char_t* buf;
ase_size_t size;
ase_size_t capa;
- ase_mmgr_t* mmgr;
- ase_bool_t __dynamic;
};
/* int ase_chartonum (ase_char_t c, int base) */
-#define ASE_CHARTONUM(c,base) \
+#define ASE_CHAR_TO_NUM(c,base) \
((c>=ASE_T('0') && c<=ASE_T('9'))? ((c-ASE_T('0')=ASE_T('A') && c<=ASE_T('Z'))? ((c-ASE_T('A')+10=ASE_T('a') && c<=ASE_T('z'))? ((c-ASE_T('a')+10mmgr = mmgr;
- str->buf = (ase_char_t*) ASE_MMGR_ALLOC (
- mmgr, sizeof(ase_char_t) * (capa + 1));
- if (str->buf == ASE_NULL) return ASE_NULL;
+
+ if (capa == 0) str->buf = ASE_NULL;
+ else
+ {
+ str->buf = (ase_char_t*) ASE_MMGR_ALLOC (
+ mmgr, sizeof(ase_char_t) * (capa + 1));
+ if (str->buf == ASE_NULL) return ASE_NULL;
+ str->buf[0] = ASE_T('\0');
+ }
str->size = 0;
- str->capa = capa;
- str->buf[0] = ASE_T('\0');
+ str->capa = capa;
return str;
}
void ase_str_fini (ase_str_t* str)
{
- ASE_MMGR_FREE (str->mmgr, str->buf);
+ if (str->buf != ASE_NULL) ASE_MMGR_FREE (str->mmgr, str->buf);
+}
+
+int ase_str_yield (ase_str_t* str, ase_cstr_t* buf, int new_capa)
+{
+ ase_char_t* tmp;
+
+ if (new_capa == 0) tmp = ASE_NULL;
+ else
+ {
+ tmp = (ase_char_t*) ASE_MMGR_ALLOC (
+ str->mmgr, sizeof(ase_char_t) * (new_capa + 1));
+ if (tmp == ASE_NULL) return -1;
+ tmp[0] = ASE_T('\0');
+ }
+
+ if (buf != ASE_NULL)
+ {
+ buf->ptr = str->buf;
+ buf->len = str->size;
+ }
+
+ str->buf = tmp;
+ str->size = 0;
+ str->capa = new_capa;
+
+ return 0;
}
void ase_str_clear (ase_str_t* str)
@@ -56,12 +87,6 @@ void ase_str_clear (ase_str_t* str)
str->buf[0] = ASE_T('\0');
}
-void ase_str_forfeit (ase_str_t* str)
-{
- // TODO: how to handle this??????????????????????
- if (str->__dynamic) ASE_MMGR_FREE (str->mmgr, str);
-}
-
void ase_str_swap (ase_str_t* str, ase_str_t* str1)
{
ase_str_t tmp;
@@ -92,13 +117,13 @@ ase_size_t ase_str_ncpy (ase_str_t* str, const ase_char_t* s, ase_size_t len)
{
ase_char_t* buf;
- if (len > str->capa)
+ if (len > str->capa || str->buf == ASE_NULL)
{
buf = (ase_char_t*) ASE_MMGR_ALLOC (
str->mmgr, sizeof(ase_char_t) * (len + 1));
if (buf == ASE_NULL) return (ase_size_t)-1;
- ASE_MMGR_FREE (str->mmgr, str->buf);
+ if (str->buf != ASE_NULL) ASE_MMGR_FREE (str->mmgr, str->buf);
str->capa = len;
str->buf = buf;
}
@@ -126,11 +151,11 @@ ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len)
/* double the capa if necessary for concatenation */
if (capa < str->capa * 2) capa = str->capa * 2;
- if (str->mmgr->realloc != ASE_NULL)
+ if (str->mmgr->realloc != ASE_NULL && str->buf != ASE_NULL)
{
tmp = (ase_char_t*) ASE_REALLOC (
str->mmgr, str->buf,
- sizeof(ase_char_t) * (capa + 1));
+ sizeof(ase_char_t)*(capa+1));
if (tmp == ASE_NULL) return (ase_size_t)-1;
}
else