1 /* 2 * Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #include "LocaleUtils.h" 6 7 #include <stdlib.h> 8 9 #include <Collator.h> 10 #include <Locale.h> 11 #include <LocaleRoster.h> 12 13 14 BCollator* LocaleUtils::sSharedCollator = NULL; 15 16 17 /*static*/ BCollator* 18 LocaleUtils::GetSharedCollator() 19 { 20 if (sSharedCollator == NULL) { 21 sSharedCollator = new BCollator(); 22 GetCollator(sSharedCollator); 23 } 24 25 return sSharedCollator; 26 } 27 28 29 /*static*/ void 30 LocaleUtils::GetCollator(BCollator* collator) 31 { 32 const BLocale* locale = BLocaleRoster::Default()->GetDefaultLocale(); 33 34 if (B_OK != locale->GetCollator(collator)) { 35 debugger("unable to get the locale's collator"); 36 exit(EXIT_FAILURE); 37 } 38 } 39