Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsCRT.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
#ifndef nsCRT_h___
7
#define nsCRT_h___
8
9
#include <stdlib.h>
10
#include <ctype.h>
11
#include "plstr.h"
12
#include "nscore.h"
13
#include "nsCRTGlue.h"
14
15
#if defined(XP_WIN)
16
#  define NS_LINEBREAK           "\015\012"
17
#  define NS_LINEBREAK_LEN       2
18
#else
19
#  ifdef XP_UNIX
20
0
#    define NS_LINEBREAK         "\012"
21
0
#    define NS_LINEBREAK_LEN     1
22
#  endif /* XP_UNIX */
23
#endif /* XP_WIN */
24
25
extern const char16_t kIsoLatin1ToUCS2[256];
26
27
/// This is a wrapper class around all the C runtime functions.
28
29
class nsCRT
30
{
31
public:
32
  enum
33
  {
34
    LF = '\n'   /* Line Feed */,
35
    VTAB = '\v' /* Vertical Tab */,
36
    CR = '\r'   /* Carriage Return */
37
  };
38
39
  /// String comparison.
40
  static int32_t strcmp(const char* aStr1, const char* aStr2)
41
  {
42
    return int32_t(PL_strcmp(aStr1, aStr2));
43
  }
44
45
  /// Case-insensitive string comparison.
46
  static int32_t strcasecmp(const char* aStr1, const char* aStr2)
47
48.3M
  {
48
48.3M
    return int32_t(PL_strcasecmp(aStr1, aStr2));
49
48.3M
  }
50
51
  /// Case-insensitive string comparison with length
52
  static int32_t strncasecmp(const char* aStr1, const char* aStr2,
53
                             uint32_t aMaxLen)
54
3.15k
  {
55
3.15k
    int32_t result = int32_t(PL_strncasecmp(aStr1, aStr2, aMaxLen));
56
3.15k
    //Egads. PL_strncasecmp is returning *very* negative numbers.
57
3.15k
    //Some folks expect -1,0,1, so let's temper its enthusiasm.
58
3.15k
    if (result < 0) {
59
1.84k
      result = -1;
60
1.84k
    }
61
3.15k
    return result;
62
3.15k
  }
63
64
  /**
65
66
    How to use this fancy (thread-safe) version of strtok:
67
68
    void main(void) {
69
      printf("%s\n\nTokens:\n", string);
70
      // Establish string and get the first token:
71
      char* newStr;
72
      token = nsCRT::strtok(string, seps, &newStr);
73
      while (token != nullptr) {
74
        // While there are tokens in "string"
75
        printf(" %s\n", token);
76
        // Get next token:
77
        token = nsCRT::strtok(newStr, seps, &newStr);
78
      }
79
    }
80
    * WARNING - STRTOK WHACKS str THE FIRST TIME IT IS CALLED *
81
    * MAKE A COPY OF str IF YOU NEED TO USE IT AFTER strtok() *
82
  */
83
  static char* strtok(char* aStr, const char* aDelims, char** aNewStr);
84
85
  /// Like strcmp except for ucs2 strings
86
  static int32_t strcmp(const char16_t* aStr1, const char16_t* aStr2);
87
88
  // String to longlong
89
  static int64_t atoll(const char* aStr);
90
91
0
  static char ToUpper(char aChar) { return NS_ToUpper(aChar); }
92
864
  static char ToLower(char aChar) { return NS_ToLower(aChar); }
93
94
0
  static bool IsUpper(char aChar) { return NS_IsUpper(aChar); }
95
0
  static bool IsLower(char aChar) { return NS_IsLower(aChar); }
96
97
0
  static bool IsAscii(char16_t aChar) { return NS_IsAscii(aChar); }
98
0
  static bool IsAscii(const char16_t* aString) { return NS_IsAscii(aString); }
99
0
  static bool IsAsciiSpace(char16_t aChar) { return NS_IsAsciiWhitespace(aChar); }
100
0
  static bool IsAscii(const char* aString) { return NS_IsAscii(aString); }
101
  static bool IsAscii(const char* aString, uint32_t aLength)
102
0
  {
103
0
    return NS_IsAscii(aString, aLength);
104
0
  }
105
};
106
107
108
inline bool
109
NS_IS_SPACE(char16_t aChar)
110
0
{
111
0
  return ((int(aChar) & 0x7f) == int(aChar)) && isspace(int(aChar));
112
0
}
113
114
#define NS_IS_CNTRL(i)   ((((unsigned int) (i)) > 0x7f) ? (int) 0 : iscntrl(i))
115
#define NS_IS_DIGIT(i)   ((((unsigned int) (i)) > 0x7f) ? (int) 0 : isdigit(i))
116
#if defined(XP_WIN)
117
#define NS_IS_ALPHA(VAL) (isascii((int)(VAL)) && isalpha((int)(VAL)))
118
#else
119
#define NS_IS_ALPHA(VAL) ((((unsigned int) (VAL)) > 0x7f) ? (int) 0 : isalpha((int)(VAL)))
120
#endif
121
122
123
#endif /* nsCRT_h___ */