parser/htmlparser/src/nsParserMsgUtils.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #include "nsIServiceManager.h"
     7 #include "nsIStringBundle.h"
     8 #include "nsXPIDLString.h"
     9 #include "nsParserMsgUtils.h"
    10 #include "nsNetCID.h"
    11 #include "mozilla/Services.h"
    13 static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle)
    14 {
    15   NS_ENSURE_ARG_POINTER(aPropFileName);
    16   NS_ENSURE_ARG_POINTER(aBundle);
    18   // Create a bundle for the localization
    20   nsCOMPtr<nsIStringBundleService> stringService =
    21     mozilla::services::GetStringBundleService();
    22   if (!stringService)
    23     return NS_ERROR_FAILURE;
    25   return stringService->CreateBundle(aPropFileName, aBundle);
    26 }
    28 nsresult
    29 nsParserMsgUtils::GetLocalizedStringByName(const char * aPropFileName, const char* aKey, nsString& oVal)
    30 {
    31   oVal.Truncate();
    33   NS_ENSURE_ARG_POINTER(aKey);
    35   nsCOMPtr<nsIStringBundle> bundle;
    36   nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
    37   if (NS_SUCCEEDED(rv) && bundle) {
    38     nsXPIDLString valUni;
    39     nsAutoString key; key.AssignWithConversion(aKey);
    40     rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni));
    41     if (NS_SUCCEEDED(rv) && valUni) {
    42       oVal.Assign(valUni);
    43     }  
    44   }
    46   return rv;
    47 }
    49 nsresult
    50 nsParserMsgUtils::GetLocalizedStringByID(const char * aPropFileName, uint32_t aID, nsString& oVal)
    51 {
    52   oVal.Truncate();
    54   nsCOMPtr<nsIStringBundle> bundle;
    55   nsresult rv = GetBundle(aPropFileName,getter_AddRefs(bundle));
    56   if (NS_SUCCEEDED(rv) && bundle) {
    57     nsXPIDLString valUni;
    58     rv = bundle->GetStringFromID(aID, getter_Copies(valUni));
    59     if (NS_SUCCEEDED(rv) && valUni) {
    60       oVal.Assign(valUni);
    61     }  
    62   }
    64   return rv;
    65 }

mercurial