Просмотр исходного кода

utils.h, utils.c - Additions to change string case

Adds strntolower() and strntoupper() to allow changing of string case when user input is incorrect or for comparison. These work on the given string in memory and do not return a new string that has been changed.
Spenser Reinhardt 12 лет назад
Родитель
Сommit
fab176aac0
2 измененных файлов с 24 добавлено и 0 удалено
  1. 20 0
      plugins/utils.c
  2. 4 0
      plugins/utils.h

+ 20 - 0
plugins/utils.c

@@ -630,3 +630,23 @@ char *fperfdata (const char *label,
 
 	return data;
 }
+
+// set entire string to lower, no need to return as it works on string in place
+void strntolower (char * test_char, int size) {
+
+        char * ptr = test_char;
+
+        for (; ptr < test_char+size; ++ptr)
+                *ptr = tolower(*ptr);
+
+}
+
+// set entire string to lower, no need to return as it works on string in place
+void strntoupper (char * test_char, int size) {
+
+        char * ptr = test_char;
+
+        for (; ptr < test_char+size; ++ptr)
+                *ptr = toupper(*ptr);
+
+}

+ 4 - 0
plugins/utils.h

@@ -118,6 +118,10 @@ char *fperfdata (const char *,
  int,
  double);
 
+/* string case changes */
+void strntoupper (char * test_char, int size);
+void strntolower (char * test_char, int size);
+
 /* The idea here is that, although not every plugin will use all of these, 
    most will or should.  Therefore, for consistency, these very common 
    options should have only these meanings throughout the overall suite */