LCOV - code coverage report
Current view: top level - xpcom/base - NSPRLogModulesParser.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 3 16 18.8 %
Date: 2017-07-14 16:53:18 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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           3 : NSPRLogModulesParser(const char* aLogModules,
      18             :                      const std::function<void(const char*, LogLevel, int32_t)>& aCallback)
      19             : {
      20           3 :   if (!aLogModules) {
      21           3 :     return;
      22             :   }
      23             : 
      24           0 :   Tokenizer parser(aLogModules, kDelimiters, kAdditionalWordChars);
      25           0 :   nsAutoCString moduleName;
      26             : 
      27             :   // Format: LOG_MODULES="Foo:2,Bar, Baz:5"
      28           0 :   while (parser.ReadWord(moduleName)) {
      29             :     // 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             :       // Check if a negative value is provided.
      34           0 :       int32_t multiplier = 1;
      35           0 :       if (parser.CheckChar([](const char aChar) { return aChar == '-'; })) {
      36           0 :         multiplier = -1;
      37             :       }
      38             : 
      39             :       // NB: If a level isn't provided after the ':' we assume the default
      40             :       //     Error level is desired. This differs from NSPR which will stop
      41             :       //     processing the log module string in this case.
      42           0 :       if (parser.ReadInteger(&levelValue)) {
      43           0 :         logLevel = ToLogLevel(levelValue * multiplier);
      44             :       }
      45             :     }
      46             : 
      47           0 :     aCallback(moduleName.get(), logLevel, levelValue);
      48             : 
      49             :     // Skip ahead to the next token.
      50           0 :     parser.SkipWhites();
      51             :   }
      52             : }
      53             : 
      54             : } // namespace mozilla

Generated by: LCOV version 1.13