michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsCRTGlue_h__ michael@0: #define nsCRTGlue_h__ michael@0: michael@0: #include "nscore.h" michael@0: michael@0: /** michael@0: * Scan a string for the first character that is *not* in a set of michael@0: * delimiters. If the string is only delimiter characters, the end of the michael@0: * string is returned. michael@0: * michael@0: * @param delims The set of delimiters (null-terminated) michael@0: * @param str The string to search (null-terminated) michael@0: */ michael@0: NS_COM_GLUE const char* michael@0: NS_strspnp(const char *delims, const char *str); michael@0: michael@0: /** michael@0: * Tokenize a string. This function is similar to the strtok function in the michael@0: * C standard library, but it does not use static variables to maintain state michael@0: * and is therefore thread and reentrancy-safe. michael@0: * michael@0: * Any leading delimiters in str are skipped. Then the string is scanned michael@0: * until an additional delimiter or end-of-string is found. The final michael@0: * delimiter is set to '\0'. michael@0: * michael@0: * @param delims The set of delimiters. michael@0: * @param str The string to search. This is an in-out parameter; it is michael@0: * reset to the end of the found token + 1, or to the michael@0: * end-of-string if there are no more tokens. michael@0: * @return The token. If no token is found (the string is only michael@0: * delimiter characters), nullptr is returned. michael@0: */ michael@0: NS_COM_GLUE char* michael@0: NS_strtok(const char *delims, char **str); michael@0: michael@0: /** michael@0: * "strlen" for char16_t strings michael@0: */ michael@0: NS_COM_GLUE uint32_t michael@0: NS_strlen(const char16_t *aString); michael@0: michael@0: /** michael@0: * "strcmp" for char16_t strings michael@0: */ michael@0: NS_COM_GLUE int michael@0: NS_strcmp(const char16_t *a, const char16_t *b); michael@0: michael@0: /** michael@0: * "strdup" for char16_t strings, uses the NS_Alloc allocator. michael@0: */ michael@0: NS_COM_GLUE char16_t* michael@0: NS_strdup(const char16_t *aString); michael@0: michael@0: /** michael@0: * "strdup", but using the NS_Alloc allocator. michael@0: */ michael@0: NS_COM_GLUE char* michael@0: NS_strdup(const char *aString); michael@0: michael@0: /** michael@0: * strndup for char16_t strings... this function will ensure that the michael@0: * new string is null-terminated. Uses the NS_Alloc allocator. michael@0: */ michael@0: NS_COM_GLUE char16_t* michael@0: NS_strndup(const char16_t *aString, uint32_t aLen); michael@0: michael@0: // The following case-conversion methods only deal in the ascii repertoire michael@0: // A-Z and a-z michael@0: michael@0: // semi-private data declarations... don't use these directly. michael@0: class NS_COM_GLUE nsLowerUpperUtils { michael@0: public: michael@0: static const unsigned char kLower2Upper[256]; michael@0: static const unsigned char kUpper2Lower[256]; michael@0: }; michael@0: michael@0: inline char NS_ToUpper(char aChar) michael@0: { michael@0: return (char)nsLowerUpperUtils::kLower2Upper[(unsigned char)aChar]; michael@0: } michael@0: michael@0: inline char NS_ToLower(char aChar) michael@0: { michael@0: return (char)nsLowerUpperUtils::kUpper2Lower[(unsigned char)aChar]; michael@0: } michael@0: michael@0: NS_COM_GLUE bool NS_IsUpper(char aChar); michael@0: NS_COM_GLUE bool NS_IsLower(char aChar); michael@0: michael@0: NS_COM_GLUE bool NS_IsAscii(char16_t aChar); michael@0: NS_COM_GLUE bool NS_IsAscii(const char16_t* aString); michael@0: NS_COM_GLUE bool NS_IsAsciiAlpha(char16_t aChar); michael@0: NS_COM_GLUE bool NS_IsAsciiDigit(char16_t aChar); michael@0: NS_COM_GLUE bool NS_IsAsciiWhitespace(char16_t aChar); michael@0: NS_COM_GLUE bool NS_IsAscii(const char* aString); michael@0: NS_COM_GLUE bool NS_IsAscii(const char* aString, uint32_t aLength); michael@0: michael@0: #ifndef XPCOM_GLUE_AVOID_NSPR michael@0: NS_COM_GLUE void NS_MakeRandomString(char *buf, int32_t bufLen); michael@0: #endif michael@0: michael@0: #define FF '\f' michael@0: #define TAB '\t' michael@0: michael@0: #define CRSTR "\015" michael@0: #define LFSTR "\012" michael@0: #define CRLF "\015\012" /* A CR LF equivalent string */ michael@0: michael@0: // We use the most restrictive filesystem as our default set of illegal filename michael@0: // characters. This is currently Windows. michael@0: #define OS_FILE_ILLEGAL_CHARACTERS "/:*?\"<>|" michael@0: // We also provide a list of all known file path separators for all filesystems. michael@0: // This can be used in replacement of FILE_PATH_SEPARATOR when you need to michael@0: // identify or replace all known path separators. michael@0: #define KNOWN_PATH_SEPARATORS "\\/" michael@0: michael@0: #if defined(XP_MACOSX) michael@0: #define FILE_PATH_SEPARATOR "/" michael@0: #elif defined(XP_WIN) michael@0: #define FILE_PATH_SEPARATOR "\\" michael@0: #elif defined(XP_UNIX) michael@0: #define FILE_PATH_SEPARATOR "/" michael@0: #else michael@0: #error need_to_define_your_file_path_separator_and_maybe_illegal_characters michael@0: #endif michael@0: michael@0: // Not all these control characters are illegal in all OSs, but we don't really michael@0: // want them appearing in filenames michael@0: #define CONTROL_CHARACTERS "\001\002\003\004\005\006\007" \ michael@0: "\010\011\012\013\014\015\016\017" \ michael@0: "\020\021\022\023\024\025\026\027" \ michael@0: "\030\031\032\033\034\035\036\037" michael@0: michael@0: #define FILE_ILLEGAL_CHARACTERS CONTROL_CHARACTERS OS_FILE_ILLEGAL_CHARACTERS michael@0: michael@0: #endif // nsCRTGlue_h__