소스 검색

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 년 전
부모
커밋
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 */