summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2006-11-06 20:39:40 +0000
committerDavid Cantrell <dcantrell@redhat.com>2006-11-06 20:39:40 +0000
commitf2377d9b86a098f2d1f46a7f15bd0020b4d73aba (patch)
tree7fd4cd5de4e4dbd22f65a58432ac04e3ee122b1e /isys
parent2ab9a461df39aacce6b30c42d6e7fac2d8e666fb (diff)
downloadanaconda-f2377d9b86a098f2d1f46a7f15bd0020b4d73aba.tar.gz
anaconda-f2377d9b86a098f2d1f46a7f15bd0020b4d73aba.tar.xz
anaconda-f2377d9b86a098f2d1f46a7f15bd0020b4d73aba.zip
* isys/str.c: Added str2case() to handle str2upper() and str2lower().
* isys/str.h: Prototype changes.
Diffstat (limited to 'isys')
-rw-r--r--isys/str.c45
-rw-r--r--isys/str.h2
2 files changed, 38 insertions, 9 deletions
diff --git a/isys/str.c b/isys/str.c
index 87f9d3c47..a85ba3d5b 100644
--- a/isys/str.c
+++ b/isys/str.c
@@ -19,16 +19,15 @@
#include "str.h"
/**
- * Convert given string to uppercase. Modifies the argument in the caller's
- * stack. If you must ask simply "why?" for this function, it's so we don't
- * need toupper() and the same for loop all over the place.
- *
- * LIMITATIONS: Only deals with ASCII character set.
+ * Called by str2upper() or str2lower() to do the actual work.
*
- * @param str String to convert to uppercase.
+ * @param str String to convert.
+ * @param lower Lower bound for the character range (e.g., a - z).
+ * @param upper Upper bound for the character range (e.g., a - z).
+ * @param shift Shift value (32 for lowercase, -32 for uppercase).
* @return Pointer to str.
*/
-char *str2upper(char *str) {
+char *str2case(char *str, char lower, char upper, int shift) {
char *tmp;
if (str == NULL)
@@ -37,8 +36,8 @@ char *str2upper(char *str) {
/* man ascii(7) */
tmp = str;
while (*tmp != '\0') {
- if (*tmp >= 'a' && *tmp <= 'z')
- *tmp -= 32;
+ if (*tmp >= lower && *tmp <= upper)
+ *tmp += shift;
tmp++;
}
@@ -46,4 +45,32 @@ char *str2upper(char *str) {
return str;
}
+/**
+ * Convert given string to uppercase. Modifies the argument in the caller's
+ * stack. If you must ask simply "why?" for this function, it's so we don't
+ * need toupper() and the same for loop all over the place.
+ *
+ * LIMITATIONS: Only deals with ASCII character set.
+ *
+ * @param str String to convert to uppercase.
+ * @return Pointer to str.
+ */
+char *str2upper(char *str) {
+ return str2case(str, 'a', 'z', -32);
+}
+
+/**
+ * Convert given string to lowercase. Modifies the argument in the caller's
+ * stack. If you must ask simply "why?" for this function, it's so we don't
+ * need tolower() and the same for loop all over the place.
+ *
+ * LIMITATIONS: Only deals with ASCII character set.
+ *
+ * @param str String to convert to lowercase.
+ * @return Pointer to str.
+ */
+char *str2lower(char *str) {
+ return str2case(str, 'A', 'Z', 32);
+}
+
/* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/str.h b/isys/str.h
index b5429a6a3..10b3d9865 100644
--- a/isys/str.h
+++ b/isys/str.h
@@ -14,6 +14,8 @@
*/
/* Function prototypes */
+char *str2case(char *str, char lower, char upper, int shift);
char *str2upper(char *str);
+char *str2lower(char *str);
/* vim:set shiftwidth=4 softtabstop=4: */