Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/base/NSPRLogModulesParser.cpp
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
7
#include "NSPRLogModulesParser.h"
8
9
#include "mozilla/Tokenizer.h"
10
11
const char kDelimiters[] = ", ";
12
const char kAdditionalWordChars[] = "_-";
13
14
namespace mozilla {
15
16
void
17
NSPRLogModulesParser(const char* aLogModules,
18
                     const std::function<void(const char*, LogLevel, int32_t)>& aCallback)
19
3
{
20
3
  if (!aLogModules) {
21
3
    return;
22
3
  }
23
0
24
0
  Tokenizer parser(aLogModules, kDelimiters, kAdditionalWordChars);
25
0
  nsAutoCString moduleName;
26
0
27
0
  // Format: LOG_MODULES="Foo:2,Bar, Baz:5"
28
0
  while (parser.ReadWord(moduleName)) {
29
0
    // Next should be :<level>, default to Error if not provided.
30
0
    LogLevel logLevel = LogLevel::Error;
31
0
    int32_t levelValue = 0;
32
0
    if (parser.CheckChar(':')) {
33
0
      // NB: If a level isn't provided after the ':' we assume the default
34
0
      //     Error level is desired. This differs from NSPR which will stop
35
0
      //     processing the log module string in this case.
36
0
      if (parser.ReadSignedInteger(&levelValue)) {
37
0
        logLevel = ToLogLevel(levelValue);
38
0
      }
39
0
    }
40
0
41
0
    aCallback(moduleName.get(), logLevel, levelValue);
42
0
43
0
    // Skip ahead to the next token.
44
0
    parser.SkipWhites();
45
0
  }
46
0
}
47
48
} // namespace mozilla