1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
13 * Scan a string for the first character that is *not* in a set of
14 * delimiters. If the string is only delimiter characters, the end of the
17 * @param aDelims The set of delimiters (null-terminated)
18 * @param aStr The string to search (null-terminated)
20 const char* NS_strspnp(const char* aDelims
, const char* aStr
);
23 * Tokenize a string. This function is similar to the strtok function in the
24 * C standard library, but it does not use static variables to maintain state
25 * and is therefore thread and reentrancy-safe.
27 * Any leading delimiters in str are skipped. Then the string is scanned
28 * until an additional delimiter or end-of-string is found. The final
29 * delimiter is set to '\0'.
31 * @param aDelims The set of delimiters.
32 * @param aStr The string to search. This is an in-out parameter; it is
33 * reset to the end of the found token + 1, or to the
34 * end-of-string if there are no more tokens.
35 * @return The token. If no token is found (the string is only
36 * delimiter characters), nullptr is returned.
38 char* NS_strtok(const char* aDelims
, char** aStr
);
41 * "strlen" for char16_t strings
43 uint32_t NS_strlen(const char16_t
* aString
);
46 * "strcmp" for char16_t strings
48 int NS_strcmp(const char16_t
* aStrA
, const char16_t
* aStrB
);
51 * "strncmp" for char16_t strings
53 int NS_strncmp(const char16_t
* aStrA
, const char16_t
* aStrB
, size_t aLen
);
56 * "strdup" for char16_t strings, uses the infallible moz_xmalloc allocator.
58 char16_t
* NS_xstrdup(const char16_t
* aString
);
61 * "strdup", but using the infallible moz_xmalloc allocator.
63 char* NS_xstrdup(const char* aString
);
66 * strndup for char16_t or char strings (normal strndup is not available on
67 * windows). This function will ensure that the new string is
68 * null-terminated. Uses the infallible moz_xmalloc allocator.
70 * CharT may be either char16_t or char.
72 template <typename CharT
>
73 CharT
* NS_xstrndup(const CharT
* aString
, uint32_t aLen
);
75 // The following case-conversion methods only deal in the ascii repertoire
78 // semi-private data declarations... don't use these directly.
79 class nsLowerUpperUtils
{
81 static const unsigned char kLower2Upper
[256];
82 static const unsigned char kUpper2Lower
[256];
85 inline char NS_ToUpper(char aChar
) {
86 return (char)nsLowerUpperUtils::kLower2Upper
[(unsigned char)aChar
];
89 inline char NS_ToLower(char aChar
) {
90 return (char)nsLowerUpperUtils::kUpper2Lower
[(unsigned char)aChar
];
93 bool NS_IsUpper(char aChar
);
94 bool NS_IsLower(char aChar
);
96 constexpr bool NS_IsAscii(const char* aString
) {
98 if (0x80 & *aString
) {
106 constexpr bool NS_IsAscii(const char* aString
, uint32_t aLength
) {
107 const char* end
= aString
+ aLength
;
108 while (aString
< end
) {
109 if (0x80 & *aString
) {
117 constexpr bool NS_IsAsciiWhitespace(char16_t aChar
) {
118 return aChar
== ' ' || aChar
== '\r' || aChar
== '\n' || aChar
== '\t';
121 #ifndef XPCOM_GLUE_AVOID_NSPR
122 void NS_MakeRandomString(char* aBuf
, int32_t aBufLen
);
130 #define CRLF "\015\012" /* A CR LF equivalent string */
133 // On mobile devices, the file system may be very limited in what it
134 // considers valid characters. To avoid errors, sanitize conservatively.
135 # define OS_FILE_ILLEGAL_CHARACTERS "/:*?\"<>|;,+=[]"
137 // Otherwise, we use the most restrictive filesystem as our default set of
138 // illegal filename characters. This is currently Windows.
139 # define OS_FILE_ILLEGAL_CHARACTERS "/:*?\"<>|"
142 // We also provide a list of all known file path separators for all filesystems.
143 // This can be used in replacement of FILE_PATH_SEPARATOR when you need to
144 // identify or replace all known path separators.
145 #define KNOWN_PATH_SEPARATORS "\\/"
147 #if defined(XP_MACOSX)
148 # define FILE_PATH_SEPARATOR "/"
149 #elif defined(XP_WIN)
150 # define FILE_PATH_SEPARATOR "\\"
151 #elif defined(XP_UNIX)
152 # define FILE_PATH_SEPARATOR "/"
154 # error need_to_define_your_file_path_separator_and_maybe_illegal_characters
157 // Not all these control characters are illegal in all OSs, but we don't really
158 // want them appearing in filenames
159 #define CONTROL_CHARACTERS \
160 "\001\002\003\004\005\006\007" \
161 "\010\011\012\013\014\015\016\017" \
162 "\020\021\022\023\024\025\026\027" \
163 "\030\031\032\033\034\035\036\037" \
165 "\200\201\202\203\204\205\206\207" \
166 "\210\211\212\213\214\215\216\217" \
167 "\220\221\222\223\224\225\226\227" \
168 "\230\231\232\233\234\235\236\237"
170 #define FILE_ILLEGAL_CHARACTERS CONTROL_CHARACTERS OS_FILE_ILLEGAL_CHARACTERS
172 #endif // nsCRTGlue_h__