diff --git a/headers/private/storage/storage_support.h b/headers/private/storage/storage_support.h index 93ad017c84..ddc2dfce68 100644 --- a/headers/private/storage/storage_support.h +++ b/headers/private/storage/storage_support.h @@ -11,6 +11,7 @@ #ifndef _STORAGE_SUPPORT_H #define _STORAGE_SUPPORT_H +#include namespace BPrivate { namespace Storage { @@ -38,6 +39,18 @@ status_t check_entry_name(const char *entry); //! Checks whether a path name is a valid path name. status_t check_path_name(const char *path); +//! Returns a copy of \c str in which all alphabetic characters are lowercase. +std::string to_lower(const char *str); + +//! Places a copy of \c str in \c result in which all alphabetic characters are lowercase. +void to_lower(const char *str, std::string &result); + +//! Copies \c str into \c result, converting any uppercase alphabetics to lowercase. +void to_lower(const char *str, char *result); + +//! Converts \c str to lowercase. +void to_lower(char *str); + }; // namespace Storage }; // namespace BPrivate diff --git a/src/kits/storage/storage_support.cpp b/src/kits/storage/storage_support.cpp index 1b1c782de8..a91c9f91b2 100644 --- a/src/kits/storage/storage_support.cpp +++ b/src/kits/storage/storage_support.cpp @@ -8,6 +8,7 @@ */ #include +#include #include #include @@ -315,6 +316,49 @@ check_path_name(const char *path) return error; } +/*! Returns "(null)" if you're a bonehead and pass in a \c NULL pointer. +*/ +std::string +to_lower(const char *str) +{ + std::string result; + to_lower(str, result); + return result; +} + +/*! Returns "(null)" if you're a bonehead and pass in a \c NULL pointer. +*/ +void +to_lower(const char *str, std::string &result) +{ + if (str) { + result = ""; + for (int i = 0; i < strlen(str); i++) + result += tolower(str[i]); + } else + result = "(null)"; +} + +/*! \c str and \c result may point to the same string. \c result is + assumed to be as long as or longer than \c str. +*/ +void +to_lower(const char *str, char *result) +{ + if (str && result) { + int i; + for (i = 0; i < strlen(str); i++) + result[i] = tolower(str[i]); + result[i] = 0; + } +} + +void +to_lower(char *str) +{ + to_lower(str, str); +} + }; // namespace Storage }; // namespace BPrivate