xpcom/glue/nsCRTGlue.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/nsCRTGlue.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,140 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsCRTGlue_h__
     1.9 +#define nsCRTGlue_h__
    1.10 +
    1.11 +#include "nscore.h"
    1.12 +
    1.13 +/**
    1.14 + * Scan a string for the first character that is *not* in a set of
    1.15 + * delimiters.  If the string is only delimiter characters, the end of the
    1.16 + * string is returned.
    1.17 + *
    1.18 + * @param delims The set of delimiters (null-terminated)
    1.19 + * @param str    The string to search (null-terminated)
    1.20 + */
    1.21 +NS_COM_GLUE const char*
    1.22 +NS_strspnp(const char *delims, const char *str);
    1.23 +
    1.24 +/**
    1.25 + * Tokenize a string. This function is similar to the strtok function in the
    1.26 + * C standard library, but it does not use static variables to maintain state
    1.27 + * and is therefore thread and reentrancy-safe.
    1.28 + *
    1.29 + * Any leading delimiters in str are skipped. Then the string is scanned
    1.30 + * until an additional delimiter or end-of-string is found. The final
    1.31 + * delimiter is set to '\0'.
    1.32 + *
    1.33 + * @param delims The set of delimiters.
    1.34 + * @param str    The string to search. This is an in-out parameter; it is
    1.35 + *               reset to the end of the found token + 1, or to the
    1.36 + *               end-of-string if there are no more tokens.
    1.37 + * @return       The token. If no token is found (the string is only
    1.38 + *               delimiter characters), nullptr is returned.
    1.39 + */
    1.40 +NS_COM_GLUE char*
    1.41 +NS_strtok(const char *delims, char **str);
    1.42 +
    1.43 +/**
    1.44 + * "strlen" for char16_t strings
    1.45 + */
    1.46 +NS_COM_GLUE uint32_t
    1.47 +NS_strlen(const char16_t *aString);
    1.48 +
    1.49 +/**
    1.50 + * "strcmp" for char16_t strings
    1.51 + */
    1.52 +NS_COM_GLUE int
    1.53 +NS_strcmp(const char16_t *a, const char16_t *b);
    1.54 +
    1.55 +/**
    1.56 + * "strdup" for char16_t strings, uses the NS_Alloc allocator.
    1.57 + */
    1.58 +NS_COM_GLUE char16_t*
    1.59 +NS_strdup(const char16_t *aString);
    1.60 +
    1.61 +/**
    1.62 + * "strdup", but using the NS_Alloc allocator.
    1.63 + */
    1.64 +NS_COM_GLUE char*
    1.65 +NS_strdup(const char *aString);
    1.66 +
    1.67 +/**
    1.68 + * strndup for char16_t strings... this function will ensure that the
    1.69 + * new string is null-terminated. Uses the NS_Alloc allocator.
    1.70 + */
    1.71 +NS_COM_GLUE char16_t*
    1.72 +NS_strndup(const char16_t *aString, uint32_t aLen);
    1.73 +
    1.74 +// The following case-conversion methods only deal in the ascii repertoire
    1.75 +// A-Z and a-z
    1.76 +
    1.77 +// semi-private data declarations... don't use these directly.
    1.78 +class NS_COM_GLUE nsLowerUpperUtils {
    1.79 +public:
    1.80 +  static const unsigned char kLower2Upper[256];
    1.81 +  static const unsigned char kUpper2Lower[256];
    1.82 +};
    1.83 +
    1.84 +inline char NS_ToUpper(char aChar)
    1.85 +{
    1.86 +  return (char)nsLowerUpperUtils::kLower2Upper[(unsigned char)aChar];
    1.87 +}
    1.88 +
    1.89 +inline char NS_ToLower(char aChar)
    1.90 +{
    1.91 +  return (char)nsLowerUpperUtils::kUpper2Lower[(unsigned char)aChar];
    1.92 +}
    1.93 +  
    1.94 +NS_COM_GLUE bool NS_IsUpper(char aChar);
    1.95 +NS_COM_GLUE bool NS_IsLower(char aChar);
    1.96 +
    1.97 +NS_COM_GLUE bool NS_IsAscii(char16_t aChar);
    1.98 +NS_COM_GLUE bool NS_IsAscii(const char16_t* aString);
    1.99 +NS_COM_GLUE bool NS_IsAsciiAlpha(char16_t aChar);
   1.100 +NS_COM_GLUE bool NS_IsAsciiDigit(char16_t aChar);
   1.101 +NS_COM_GLUE bool NS_IsAsciiWhitespace(char16_t aChar);
   1.102 +NS_COM_GLUE bool NS_IsAscii(const char* aString);
   1.103 +NS_COM_GLUE bool NS_IsAscii(const char* aString, uint32_t aLength);
   1.104 +
   1.105 +#ifndef XPCOM_GLUE_AVOID_NSPR
   1.106 +NS_COM_GLUE void NS_MakeRandomString(char *buf, int32_t bufLen);
   1.107 +#endif
   1.108 +
   1.109 +#define FF '\f'
   1.110 +#define TAB '\t'
   1.111 +
   1.112 +#define CRSTR "\015"
   1.113 +#define LFSTR "\012"
   1.114 +#define CRLF "\015\012"     /* A CR LF equivalent string */
   1.115 +
   1.116 +// We use the most restrictive filesystem as our default set of illegal filename
   1.117 +// characters. This is currently Windows.
   1.118 +#define OS_FILE_ILLEGAL_CHARACTERS "/:*?\"<>|"
   1.119 +// We also provide a list of all known file path separators for all filesystems.
   1.120 +// This can be used in replacement of FILE_PATH_SEPARATOR when you need to
   1.121 +// identify or replace all known path separators.
   1.122 +#define KNOWN_PATH_SEPARATORS "\\/"
   1.123 +
   1.124 +#if defined(XP_MACOSX)
   1.125 +  #define FILE_PATH_SEPARATOR        "/"
   1.126 +#elif defined(XP_WIN)
   1.127 +  #define FILE_PATH_SEPARATOR        "\\"
   1.128 +#elif defined(XP_UNIX)
   1.129 +  #define FILE_PATH_SEPARATOR        "/"
   1.130 +#else
   1.131 +  #error need_to_define_your_file_path_separator_and_maybe_illegal_characters
   1.132 +#endif
   1.133 +
   1.134 +// Not all these control characters are illegal in all OSs, but we don't really
   1.135 +// want them appearing in filenames
   1.136 +#define CONTROL_CHARACTERS     "\001\002\003\004\005\006\007" \
   1.137 +                           "\010\011\012\013\014\015\016\017" \
   1.138 +                           "\020\021\022\023\024\025\026\027" \
   1.139 +                           "\030\031\032\033\034\035\036\037"
   1.140 +
   1.141 +#define FILE_ILLEGAL_CHARACTERS CONTROL_CHARACTERS OS_FILE_ILLEGAL_CHARACTERS
   1.142 +
   1.143 +#endif // nsCRTGlue_h__

mercurial