Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/parser/htmlparser/nsParserMsgUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "nsIServiceManager.h"
7
#include "nsIStringBundle.h"
8
#include "nsString.h"
9
#include "nsParserMsgUtils.h"
10
#include "nsNetCID.h"
11
#include "mozilla/Services.h"
12
13
static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle)
14
0
{
15
0
  NS_ENSURE_ARG_POINTER(aPropFileName);
16
0
  NS_ENSURE_ARG_POINTER(aBundle);
17
0
18
0
  // Create a bundle for the localization
19
0
20
0
  nsCOMPtr<nsIStringBundleService> stringService =
21
0
    mozilla::services::GetStringBundleService();
22
0
  if (!stringService)
23
0
    return NS_ERROR_FAILURE;
24
0
25
0
  return stringService->CreateBundle(aPropFileName, aBundle);
26
0
}
27
28
nsresult
29
nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& oVal)
30
0
{
31
0
  oVal.Truncate();
32
0
33
0
  NS_ENSURE_ARG_POINTER(aKey);
34
0
35
0
  nsCOMPtr<nsIStringBundle> bundle;
36
0
  nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
37
0
  if (NS_SUCCEEDED(rv) && bundle) {
38
0
    nsAutoString valUni;
39
0
    rv = bundle->GetStringFromName(aKey, valUni);
40
0
    if (NS_SUCCEEDED(rv)) {
41
0
      oVal.Assign(valUni);
42
0
    }
43
0
  }
44
0
45
0
  return rv;
46
0
}
47
48
nsresult
49
nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName, uint32_t aID, nsString& oVal)
50
0
{
51
0
  oVal.Truncate();
52
0
53
0
  nsCOMPtr<nsIStringBundle> bundle;
54
0
  nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
55
0
  if (NS_SUCCEEDED(rv) && bundle) {
56
0
    nsAutoString valUni;
57
0
    rv = bundle->GetStringFromID(aID, valUni);
58
0
    if (NS_SUCCEEDED(rv)) {
59
0
      oVal.Assign(valUni);
60
0
    }
61
0
  }
62
0
63
0
  return rv;
64
0
}