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 "nsCollationFactory.h"
7 #include "nsCollation.h"
8 #include "nsServiceManagerUtils.h"
9 #include "mozilla/intl/LocaleService.h"
10 
11 ////////////////////////////////////////////////////////////////////////////////
12 
NS_IMPL_ISUPPORTS(nsCollationFactory,nsICollationFactory)13 NS_IMPL_ISUPPORTS(nsCollationFactory, nsICollationFactory)
14 
15 nsresult nsCollationFactory::CreateCollation(nsICollation** instancePtr) {
16   nsAutoCString appLocale;
17   mozilla::intl::LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale);
18 
19   return CreateCollationForLocale(appLocale, instancePtr);
20 }
21 
CreateCollationForLocale(const nsACString & locale,nsICollation ** instancePtr)22 nsresult nsCollationFactory::CreateCollationForLocale(
23     const nsACString& locale, nsICollation** instancePtr) {
24   // Create a collation interface instance.
25   //
26   nsCOMPtr<nsICollation> inst = new nsCollation();
27 
28   inst->Initialize(locale);
29 
30   inst.forget(instancePtr);
31 
32   return NS_OK;
33 }
34