summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/custmenu.cpp
blob: ea5562a0d9e4f28a864796cf770c092c9661e87e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// license:BSD-3-Clause
// copyright-holders:Maurizio Petrarota
/*********************************************************************

    ui/custmenu.cpp

    Internal UI user interface.

*********************************************************************/

#include "emu.h"
#include "ui/custmenu.h"

#include <algorithm>


namespace ui {

namespace {

constexpr char const *region_lists[] = {
		"arab", "arg", "asia", "aus", "aut",
		"bel", "blr", "bra",
		"can", "chi", "chn", "cze",
		"den",
		"ecu", "esp", "euro",
		"fin", "fra",
		"gbr", "ger", "gre",
		"hkg", "hun",
		"irl", "isr", "isv", "ita",
		"jpn",
		"kaz", "kor",
		"lat", "lux",
		"mex",
		"ned", "nld", "nor", "nzl",
		"pol",
		"rus",
		"slo", "spa", "sui", "swe",
		"tha", "tpe", "tw",
		"uk", "ukr", "usa" };

} // anonymous namespace

//-------------------------------------------------
//  set software regions
//-------------------------------------------------

void c_sw_region::set(std::string &str)
{
	std::string name(getname(str));
	std::vector<std::string>::iterator const pos(std::lower_bound(ui.begin(), ui.end(), name));
	if ((ui.end() == pos) || (*pos != str))
		ui.emplace(pos, std::move(name));
}

std::string c_sw_region::getname(std::string const &str) const
{
	std::string fullname(str);
	strmakelower(fullname);
	size_t found = fullname.find("(");

	if (found != std::string::npos)
	{
		size_t ends = fullname.find_first_not_of("abcdefghijklmnopqrstuvwxyz", found + 1);
		std::string temp(fullname.substr(found + 1, ends - found - 1));

		for (auto & elem : region_lists)
			if (temp == elem)
				return (str.substr(found + 1, ends - found - 1));
	}
	return std::string("<none>");
}

//-------------------------------------------------
//  set software device type
//-------------------------------------------------

void c_sw_type::set(std::string &str)
{
	std::vector<std::string>::iterator const pos(std::lower_bound(ui.begin(), ui.end(), str));
	if ((ui.end() == pos) || (*pos != str))
		ui.emplace(pos, str);
}

//-------------------------------------------------
//  set software years
//-------------------------------------------------

void c_sw_year::set(std::string &str)
{
	std::vector<std::string>::iterator const pos(std::lower_bound(ui.begin(), ui.end(), str));
	if ((ui.end() == pos) || (*pos != str))
		ui.emplace(pos, str);
}

//-------------------------------------------------
//  set software publishers
//-------------------------------------------------

void c_sw_publisher::set(std::string &str)
{
	std::string name(getname(str));
	std::vector<std::string>::iterator const pos(std::lower_bound(ui.begin(), ui.end(), name));
	if ((ui.end() == pos) || (*pos != str))
		ui.emplace(pos, std::move(name));
}

std::string c_sw_publisher::getname(std::string const &str) const
{
	size_t found = str.find("(");

	if (found != std::string::npos)
		return (str.substr(0, found - 1));
	else
		return str;
}

} // namespace ui