/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsCRT_h___ #define nsCRT_h___
/// Case-insensitive string comparison. static int32_t strcasecmp(constchar* aStr1, constchar* aStr2) { /* Some functions like `PL_strcasecmp` are reimplementations * of the their native POSIX counterparts, which breaks libFuzzer. * For this purpose, we use the natives instead when fuzzing.
*/ #ifdefined(LIBFUZZER) && defined(LINUX) return int32_t(::strcasecmp(aStr1, aStr2)); #else return int32_t(PL_strcasecmp(aStr1, aStr2)); #endif
}
/// Case-insensitive string comparison with length static int32_t strncasecmp(constchar* aStr1, constchar* aStr2,
uint32_t aMaxLen) { #ifdefined(LIBFUZZER) && defined(LINUX)
int32_t result = int32_t(::strncasecmp(aStr1, aStr2, aMaxLen)); #else
int32_t result = int32_t(PL_strncasecmp(aStr1, aStr2, aMaxLen)); #endif // Egads. PL_strncasecmp is returning *very* negative numbers. // Some folks expect -1,0,1, so let's temper its enthusiasm. if (result < 0) {
result = -1;
} return result;
}
How to use this fancy (thread-safe) version of strtok:
void main(void) { printf("%s\n\nTokens:\n", string); // Establish string and get the first token: char* newStr; token = nsCRT::strtok(string, seps, &newStr); while (token != nullptr) { // While there are tokens in "string" printf(" %s\n", token); // Get next token: token = nsCRT::strtok(newStr, seps, &newStr); } } * WARNING - STRTOK WHACKS str THE FIRST TIME IT IS CALLED * * MAKE A COPY OF str IF YOU NEED TO USE IT AFTER strtok() *
*/ staticchar* strtok(char* aStr, constchar* aDelims, char** aNewStr);
/// Like strcmp except for ucs2 strings static int32_t strcmp(const char16_t* aStr1, const char16_t* aStr2);
// String to longlong static int64_t atoll(constchar* aStr);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.