mirror of
https://github.com/kevinbentley/Descent3.git
synced 2026-04-14 05:00:03 -04:00
misc: pstring: Remove unneccesary or unused functions.
This commit is contained in:
@@ -39,38 +39,9 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "pstring.h"
|
||||
|
||||
#ifdef __LINUX__
|
||||
#include "lnxfix.h"
|
||||
#endif
|
||||
|
||||
// Pvsprintf
|
||||
// Similar to vsprintf/_vsnprintf, however handles the case of a buffer overflow. Arguments are the
|
||||
// same as _vsnprintf. In the case of count, pass in the size of the buffer, in the case where there is
|
||||
// a buffer overflow, a \0 will be tacked on as the last byte in the buffer, ensuring a valid string.
|
||||
int Pvsprintf(char *buffer, int count, const char *format, va_list argptr) {
|
||||
int ret = _vsnprintf(buffer, count - 1, format, argptr);
|
||||
if (ret == -1)
|
||||
buffer[count - 1] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Psprintf
|
||||
// Similar to sprintf/_snprintf, however handles the case of a buffer overflow. Arguments are the
|
||||
// same as _snprintf. In the case of count, pass in the size of the buffer, in the case where there is
|
||||
// a buffer overflow, a \0 will be tacked on as the last byte in the buffer, ensuring a valid string.
|
||||
int Psprintf(char *buffer, int count, const char *format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int ret = Pvsprintf(buffer, count, format, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// CleanupStr
|
||||
// this function strips all leading and trailing spaces, keeping internal spaces. this goes
|
||||
// for tabs too.
|
||||
@@ -111,67 +82,3 @@ int CleanupStr(char *dest, const char *src, int destlen) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// tStringTok
|
||||
// you may start a string tokenization object by calling the start function
|
||||
// then call next, to get the following tokens.
|
||||
// note that this class uses it's own copy of the string to ensure that strtok doesn't
|
||||
// get corrupted.
|
||||
|
||||
tStringTok::~tStringTok() {
|
||||
if (m_strbuf)
|
||||
delete[] m_strbuf;
|
||||
}
|
||||
|
||||
char *tStringTok::start(const char *str, const char *tokens) {
|
||||
// if we pass a null string, then reset this object
|
||||
if (str == NULL) {
|
||||
if (m_strbuf)
|
||||
delete[] m_strbuf;
|
||||
m_strbuf = NULL;
|
||||
m_curptr = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *new_str = new char[strlen(str) + 1];
|
||||
|
||||
// copy string into new string buffer. AFTER THIS, delete the current string buffer, since the pointer
|
||||
// passed in could point to the current m_strbuf ptr.
|
||||
strcpy(new_str, str);
|
||||
|
||||
if (m_strbuf)
|
||||
delete[] m_strbuf;
|
||||
m_strbuf = new_str;
|
||||
m_curptr = m_strbuf;
|
||||
|
||||
return this->next(tokens);
|
||||
}
|
||||
|
||||
char *tStringTok::next(const char *tokens) {
|
||||
// create string by terminating m_strbuf when a token is it.
|
||||
char *cur_str, *end_str;
|
||||
int slen2, j;
|
||||
|
||||
if (!m_curptr)
|
||||
return m_curptr;
|
||||
|
||||
slen2 = strlen(tokens);
|
||||
cur_str = NULL;
|
||||
|
||||
for (j = 0; j < slen2; j++) {
|
||||
end_str = strchr(m_curptr, tokens[j]);
|
||||
if (end_str) {
|
||||
*end_str = 0;
|
||||
cur_str = m_curptr;
|
||||
m_curptr = end_str + 1;
|
||||
return cur_str;
|
||||
}
|
||||
}
|
||||
// at this point, we found no tokens, so m_curptr will point to the string we want to return.
|
||||
// then we set m_curptr to NULL, telling any subsequent calls to next to return NULL.
|
||||
|
||||
cur_str = m_curptr;
|
||||
m_curptr = NULL;
|
||||
|
||||
return cur_str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user