source: branches/work_320/lists/support/UTF8StringList.cpp @ 677

Revision 677, 2.5 KB checked in by jls17, 5 years ago (diff)
  • the sorting does now use lower-case-values again
  • fixed compile errors because of missing stdexcept include
  • updated IndexSorter? tests
  • updated ARInside.vsproj file regarding breakpad-support
Line 
1//Copyright (C) 2014 John Luthgers | jls17
2//
3//This file is part of ARInside.
4//
5//    ARInside is free software: you can redistribute it and/or modify
6//    it under the terms of the GNU General Public License as published by
7//    the Free Software Foundation, version 2 of the License.
8//
9//    ARInside is distributed in the hope that it will be useful,
10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12//    GNU General Public License for more details.
13//
14//    You should have received a copy of the GNU General Public License
15//    along with ARInside.  If not, see <http://www.gnu.org/licenses/>.
16
17#include "stdafx.h"
18#include "UTF8StringList.h"
19#include "thirdparty/utf8cpp/source/utf8.h"
20#include <locale>
21
22UTF8StringList::UTF8StringList()
23#ifdef WIN32
24#define UTF8_SORT_LOCALE systemLocale
25: systemLocale(""), coll(std::use_facet<std::collate<sort_char_t> >(UTF8_SORT_LOCALE))
26#else
27#define UTF8_SORT_LOCALE localeDetection.sortLocale
28: coll(std::use_facet<std::collate<char> >(UTF8_SORT_LOCALE))
29#endif
30{
31}
32
33void UTF8StringList::Allocate(unsigned int size)
34{
35        list.reserve(size);
36}
37
38void UTF8StringList::PushBack(ARNameType &value)
39{
40        unsigned int skippedSpaces = 0;
41        while (value[skippedSpaces] == ' ') skippedSpaces++;
42
43#ifdef WIN32
44        std::wstring wideString;
45        wideString.reserve(AR_MAX_NAME_SIZE + 1);
46        utf8::utf8to16(&value[skippedSpaces], &value[strlen(value)], back_inserter(wideString));
47        MakeLower(wideString);
48
49        list.push_back(wideString);
50#else
51        list.push_back(&value[skippedSpaces]);
52#endif
53}
54
55void UTF8StringList::PushBack(const std::string &value)
56{
57        unsigned int skippedSpaces = 0;
58        while (value[skippedSpaces] == ' ') skippedSpaces++;
59
60#ifdef WIN32
61        std::wstring wideString;
62        wideString.reserve(AR_MAX_NAME_SIZE + 1);
63        utf8::utf8to16(value.begin() + skippedSpaces, value.end(), back_inserter(wideString));
64        MakeLower(wideString);
65       
66        list.push_back(wideString);
67#else
68        list.push_back(value.c_str() + skippedSpaces);
69#endif
70}
71
72bool UTF8StringList::operator() (int l, int r)
73{
74        return (
75                coll.compare(list[l].c_str(), list[l].c_str() + list[l].size(),
76                             list[r].c_str(), list[r].c_str() + list[r].size()
77                            ) < 0);
78}
79
80UTF8StringList::sort_char_t UTF8StringList::operator () (sort_char_t c)
81{
82        return std::tolower(c, UTF8_SORT_LOCALE);
83}
84
85void UTF8StringList::MakeLower(list_string_t &str)
86{
87        std::transform(str.begin(), str.end(), str.begin(), *this);
88}
Note: See TracBrowser for help on using the repository browser.