mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[util] Use size_t for dstring length params
While not overly wrong, unsigned is not really appropriate.
This commit is contained in:
parent
0167456b21
commit
7c788a6e7a
2 changed files with 34 additions and 36 deletions
|
@ -45,8 +45,8 @@ typedef struct dstring_mem_s {
|
|||
|
||||
typedef struct dstring_s {
|
||||
dstring_mem_t *mem;
|
||||
unsigned long int size, truesize;
|
||||
char *str;
|
||||
size_t size, truesize;
|
||||
char *str;
|
||||
} dstring_t;
|
||||
|
||||
extern dstring_mem_t dstring_default_mem;
|
||||
|
@ -72,21 +72,21 @@ void dstring_adjust (dstring_t *dstr);
|
|||
\param len the size of the hole to open.
|
||||
\return pointer to the beginning of the opened hole.
|
||||
*/
|
||||
char *dstring_reserve (dstring_t *dstr, unsigned len);
|
||||
char *dstring_reserve (dstring_t *dstr, size_t len);
|
||||
/** Copy len bytes from data into the dstring, replacing any existing data.
|
||||
*/
|
||||
void dstring_copy (dstring_t *dstr, const char *data, unsigned int len);
|
||||
void dstring_copy (dstring_t *dstr, const char *data, size_t len);
|
||||
/** Append len bytes from data onto the end of the dstring.
|
||||
*/
|
||||
void dstring_append (dstring_t *dstr, const char *data, unsigned int len);
|
||||
void dstring_append (dstring_t *dstr, const char *data, size_t len);
|
||||
/** Insert len bytes from data int the dstring at pos. If pos is past the
|
||||
end of the dstring, equivalent to dstring_append.
|
||||
*/
|
||||
void dstring_insert (dstring_t *dstr, unsigned int pos, const char *data,
|
||||
unsigned int len);
|
||||
void dstring_insert (dstring_t *dstr, size_t pos, const char *data,
|
||||
size_t len);
|
||||
/** Remove len bytes from the dstring starting at pos.
|
||||
*/
|
||||
void dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len);
|
||||
void dstring_snip (dstring_t *dstr, size_t pos, size_t len);
|
||||
/** Set the size of the dstring to 0 bytes. Does not free the string buffer
|
||||
anticipating reuse.
|
||||
*/
|
||||
|
@ -94,8 +94,8 @@ void dstring_clear (dstring_t *dstr);
|
|||
/** Replace rlen bytes in dstring at pos with len bytes from data. Moves
|
||||
trailing bytes as needed.
|
||||
*/
|
||||
void dstring_replace (dstring_t *dstr, unsigned int pos, unsigned int rlen,
|
||||
const char *data, unsigned int len);
|
||||
void dstring_replace (dstring_t *dstr, size_t pos, size_t rlen,
|
||||
const char *data, size_t len);
|
||||
/** Delete the dstring object retaining the string buffer. The string buffer
|
||||
will be just big enough to hold the data. Does NOT ensure the string is
|
||||
null terminated.
|
||||
|
@ -123,7 +123,7 @@ dstring_t *dstring_strdup (const char *str);
|
|||
\return pointer to the current null terminator or beginning of the
|
||||
opened hole if there was no terminator.
|
||||
*/
|
||||
char *dstring_reservestr (dstring_t *dstr, unsigned len);
|
||||
char *dstring_reservestr (dstring_t *dstr, size_t len);
|
||||
/** Copy the null terminated string into the dstring. Replaces any existing
|
||||
data.
|
||||
The dstring does not have to be null terminated but will become so.
|
||||
|
@ -133,7 +133,7 @@ void dstring_copystr (dstring_t *dstr, const char *str);
|
|||
existing data.
|
||||
The dstring does not have to be null terminated but will become so.
|
||||
*/
|
||||
void dstring_copysubstr (dstring_t *dstr, const char *str, unsigned int len);
|
||||
void dstring_copysubstr (dstring_t *dstr, const char *str, size_t len);
|
||||
/** Append the null terminated string to the end of the dstring.
|
||||
The dstring does not have to be null terminated but will become so.
|
||||
However, any embedded nulls will be treated as the end of the dstring.
|
||||
|
@ -143,16 +143,16 @@ void dstring_appendstr (dstring_t *dstr, const char *str);
|
|||
The dstring does not have to be null terminated but will become so.
|
||||
However, any embedded nulls will be treated as the end of the dstring.
|
||||
*/
|
||||
void dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len);
|
||||
void dstring_appendsubstr (dstring_t *dstr, const char *str, size_t len);
|
||||
/** Insert the null terminated string into the dstring at pos. The dstring
|
||||
is NOT forced to be null terminated.
|
||||
*/
|
||||
void dstring_insertstr (dstring_t *dstr, unsigned int pos, const char *str);
|
||||
void dstring_insertstr (dstring_t *dstr, size_t pos, const char *str);
|
||||
/** Insert up to len bytes from the string into the dstring at pos. The
|
||||
dstring is NOT forced to be null terminated.
|
||||
*/
|
||||
void dstring_insertsubstr (dstring_t *dstr, unsigned int pos, const char *str,
|
||||
unsigned int len);
|
||||
void dstring_insertsubstr (dstring_t *dstr, size_t pos, const char *str,
|
||||
size_t len);
|
||||
/** Clear the dstring to be equivalent to "". Does not resize the string buffer
|
||||
but size is set to 1.
|
||||
dstr = dstring_new (); dstring_clearstr (dstr); is exactly equivalent to
|
||||
|
|
|
@ -101,7 +101,7 @@ dstring_adjust (dstring_t *dstr)
|
|||
}
|
||||
|
||||
VISIBLE char *
|
||||
dstring_reserve (dstring_t *dstr, unsigned len)
|
||||
dstring_reserve (dstring_t *dstr, size_t len)
|
||||
{
|
||||
dstr->size += len;
|
||||
dstring_adjust (dstr);
|
||||
|
@ -109,7 +109,7 @@ dstring_reserve (dstring_t *dstr, unsigned len)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_copy (dstring_t *dstr, const char *data, unsigned int len)
|
||||
dstring_copy (dstring_t *dstr, const char *data, size_t len)
|
||||
{
|
||||
dstr->size = len;
|
||||
dstring_adjust (dstr);
|
||||
|
@ -117,9 +117,9 @@ dstring_copy (dstring_t *dstr, const char *data, unsigned int len)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_append (dstring_t *dstr, const char *data, unsigned int len)
|
||||
dstring_append (dstring_t *dstr, const char *data, size_t len)
|
||||
{
|
||||
unsigned int ins = dstr->size; // Save insertion point
|
||||
size_t ins = dstr->size; // Save insertion point
|
||||
|
||||
dstr->size += len;
|
||||
dstring_adjust (dstr);
|
||||
|
@ -127,10 +127,9 @@ dstring_append (dstring_t *dstr, const char *data, unsigned int len)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_insert (dstring_t *dstr, unsigned int pos, const char *data,
|
||||
unsigned int len)
|
||||
dstring_insert (dstring_t *dstr, size_t pos, const char *data, size_t len)
|
||||
{
|
||||
unsigned int oldsize = dstr->size;
|
||||
size_t oldsize = dstr->size;
|
||||
|
||||
if (pos > dstr->size)
|
||||
pos = dstr->size;
|
||||
|
@ -141,7 +140,7 @@ dstring_insert (dstring_t *dstr, unsigned int pos, const char *data,
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len)
|
||||
dstring_snip (dstring_t *dstr, size_t pos, size_t len)
|
||||
{
|
||||
if (pos > dstr->size)
|
||||
pos = dstr->size;
|
||||
|
@ -162,10 +161,10 @@ dstring_clear (dstring_t *dstr)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_replace (dstring_t *dstr, unsigned int pos, unsigned int rlen,
|
||||
const char *data, unsigned int len)
|
||||
dstring_replace (dstring_t *dstr, size_t pos, size_t rlen,
|
||||
const char *data, size_t len)
|
||||
{
|
||||
unsigned int oldsize = dstr->size;
|
||||
size_t oldsize = dstr->size;
|
||||
if (pos > dstr->size)
|
||||
pos = dstr->size;
|
||||
if (rlen > dstr->size - pos)
|
||||
|
@ -223,7 +222,7 @@ dstring_strdup (const char *str)
|
|||
}
|
||||
|
||||
VISIBLE char *
|
||||
dstring_reservestr (dstring_t *dstr, unsigned len)
|
||||
dstring_reservestr (dstring_t *dstr, size_t len)
|
||||
{
|
||||
int pos = dstr->size;
|
||||
if (pos && !dstr->str[pos - 1])
|
||||
|
@ -242,7 +241,7 @@ dstring_copystr (dstring_t *dstr, const char *str)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_copysubstr (dstring_t *dstr, const char *str, unsigned int len)
|
||||
dstring_copysubstr (dstring_t *dstr, const char *str, size_t len)
|
||||
{
|
||||
len = strnlen (str, len);
|
||||
|
||||
|
@ -255,8 +254,8 @@ dstring_copysubstr (dstring_t *dstr, const char *str, unsigned int len)
|
|||
VISIBLE void
|
||||
dstring_appendstr (dstring_t *dstr, const char *str)
|
||||
{
|
||||
unsigned int pos = strnlen (dstr->str, dstr->size);
|
||||
unsigned int len = strlen (str);
|
||||
size_t pos = strnlen (dstr->str, dstr->size);
|
||||
size_t len = strlen (str);
|
||||
|
||||
dstr->size = pos + len + 1;
|
||||
dstring_adjust (dstr);
|
||||
|
@ -264,9 +263,9 @@ dstring_appendstr (dstring_t *dstr, const char *str)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len)
|
||||
dstring_appendsubstr (dstring_t *dstr, const char *str, size_t len)
|
||||
{
|
||||
unsigned int pos = strnlen (dstr->str, dstr->size);
|
||||
size_t pos = strnlen (dstr->str, dstr->size);
|
||||
|
||||
len = strnlen (str, len);
|
||||
dstr->size = pos + len + 1;
|
||||
|
@ -276,15 +275,14 @@ dstring_appendsubstr (dstring_t *dstr, const char *str, unsigned int len)
|
|||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_insertstr (dstring_t *dstr, unsigned int pos, const char *str)
|
||||
dstring_insertstr (dstring_t *dstr, size_t pos, const char *str)
|
||||
{
|
||||
// Don't insert strlen + 1 to achieve concatenation
|
||||
dstring_insert (dstr, pos, str, strlen (str));
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_insertsubstr (dstring_t *dstr, unsigned int pos, const char *str,
|
||||
unsigned int len)
|
||||
dstring_insertsubstr (dstring_t *dstr, size_t pos, const char *str, size_t len)
|
||||
{
|
||||
len = strnlen (str, len);
|
||||
|
||||
|
|
Loading…
Reference in a new issue