btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / shared / NaturalCompare.cpp
blob6c60b75cf661ae280b8302a616de5adfe2894bf6
1 /*
2 * Copyright 2009, Dana Burkart
3 * Copyright 2009, Stephan Aßmus <superstippi@gmx.de>
4 * Copyright 2010, Axel Dörfler, axeld@pinc-software.de
5 * Copyright 2010, Rene Gollent (anevilyak@gmail.com)
6 * Distributed under the terms of the MIT License.
7 */
10 #include <NaturalCompare.h>
12 #include <ctype.h>
13 #include <string.h>
14 #include <strings.h>
16 #include <Collator.h>
17 #include <Locale.h>
20 namespace BPrivate {
23 // #pragma mark - Natural sorting
26 //! Compares two strings naturally, as opposed to lexicographically
27 int
28 NaturalCompare(const char* stringA, const char* stringB)
30 static BCollator* collator = NULL;
32 if (collator == NULL)
34 collator = new BCollator();
35 BLocale::Default()->GetCollator(collator);
36 collator->SetStrength(B_COLLATE_SECONDARY);
37 collator->SetNumericSorting(true);
40 return collator->Compare(stringA, stringB);
44 } // namespace BPrivate