mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 18:01:15 +00:00
[gamecode] Add function to test if string exists
As it returns the string id, it is useful for getting an string id without risking creating a new one.
This commit is contained in:
parent
686fc4c43e
commit
59f48e5e32
2 changed files with 25 additions and 0 deletions
|
@ -1290,6 +1290,15 @@ struct dstring_s *PR_GetMutableString(progs_t *pr, string_t num) __attribute__((
|
|||
*/
|
||||
string_t PR_SetString(progs_t *pr, const char *s);
|
||||
|
||||
/** Get the progs string if it exists.
|
||||
Only static strings are searched.
|
||||
\param pr pointer to ::progs_t VM struct
|
||||
\param s C string to be found
|
||||
\return string index of the progs string if it exists, otherwise
|
||||
0 (ambiguous with "").
|
||||
*/
|
||||
string_t PR_FindString(progs_t *pr, const char *s);
|
||||
|
||||
/** Make a temporary progs string that will survive across function returns.
|
||||
Will not duplicate a permanent string. If a new progs string is created,
|
||||
it will be freed after ::PR_RS_SLOTS calls to this function. ie, up to
|
||||
|
|
|
@ -440,6 +440,22 @@ PR_SetString (progs_t *pr, const char *s)
|
|||
return string_index (res, sr);
|
||||
}
|
||||
|
||||
VISIBLE string_t
|
||||
PR_FindString (progs_t *pr, const char *s)
|
||||
{
|
||||
prstr_resources_t *res = pr->pr_string_resources;
|
||||
strref_t *sr;
|
||||
|
||||
if (!s)
|
||||
s = "";
|
||||
sr = Hash_Find (res->strref_hash, s);
|
||||
|
||||
if (sr) {
|
||||
return string_index (res, sr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
VISIBLE string_t
|
||||
PR_SetReturnString (progs_t *pr, const char *s)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue