renamed function to allocate and copy memory
[rocksndiamonds.git] / src / libgame / misc.c
index c84cefc01034734b61a72fe7f468c50b03b08f56..ed22f2c09544dcdd8ed45818a44bf7349edd024f 100644 (file)
@@ -1220,6 +1220,18 @@ char *getStringCopyNStatic(const char *s, int n)
   return s_copy;
 }
 
+char *getStringToUpper(const char *s)
+{
+  char *s_copy = checked_malloc(strlen(s) + 1);
+  char *s_ptr = s_copy;
+
+  while (*s)
+    *s_ptr++ = toupper(*s++);
+  *s_ptr = '\0';
+
+  return s_copy;
+}
+
 char *getStringToLower(const char *s)
 {
   char *s_copy = checked_malloc(strlen(s) + 1);
@@ -1411,6 +1423,44 @@ char *getUnescapedString(const char *s)
   return s_unescaped;
 }
 
+char *chugString(char *s)
+{
+  if (s == NULL)
+    return NULL;
+
+  char *start;
+
+  for (start = (char *)s; *start && isspace(*start); start++)
+    ;
+
+  memmove(s, start, strlen(start) + 1);
+
+  return s;
+}
+
+char *chompString(char *s)
+{
+  if (s == NULL)
+    return NULL;
+
+  int len = strlen(s);
+
+  while (len--)
+  {
+    if (isspace(s[len]))
+      s[len] = '\0';
+    else
+      break;
+  }
+
+  return s;
+}
+
+char *stripString(char *s)
+{
+  return chugString(chompString(s));
+}
+
 boolean strEqual(const char *s1, const char *s2)
 {
   return (s1 == NULL && s2 == NULL ? TRUE  :
@@ -1834,6 +1884,19 @@ void clear_mem(void *ptr, unsigned int size)
 #endif
 }
 
+void *get_memcpy(const void *m, size_t size)
+{
+  void *m_copy;
+
+  if (m == NULL)
+    return NULL;
+
+  m_copy = checked_malloc(size);
+  memcpy(m_copy, m, size);
+
+  return m_copy;
+}
+
 
 // ----------------------------------------------------------------------------
 // various helper functions