forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroup.cpp
78 lines (64 loc) · 1.84 KB
/
Group.cpp
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
/* Copyright (C) 2010 Rainmeter Project Developers
*
* This Source Code Form is subject to the terms of the GNU General Public
* License; either version 2 of the License, or (at your option) any later
* version. If a copy of the GPL was not distributed with this file, You can
* obtain one at <https://www.gnu.org/licenses/gpl-2.0.html>. */
#include "StdAfx.h"
#include "Group.h"
#include "ConfigParser.h"
void Group::InitializeGroup(const std::wstring& groups)
{
if (wcscmp(groups.c_str(), m_OldGroups.c_str()) != 0)
{
m_OldGroups = groups;
m_Groups.clear();
if (!groups.empty())
{
std::vector<std::wstring> vGroups = ConfigParser::Tokenize(groups, L"|");
for (auto iter = vGroups.begin(); iter != vGroups.end(); ++iter)
{
m_Groups.insert(CreateGroup(*iter));
}
}
}
}
bool Group::AddToGroup(const std::wstring& group)
{
if (!group.empty() && !BelongsToGroup(group))
{
if (!m_OldGroups.empty())
{
m_OldGroups.append(1, L'|');
}
m_OldGroups.append(group);
std::vector<std::wstring> vGroups = ConfigParser::Tokenize(group, L"|");
for (auto iter = vGroups.begin(); iter != vGroups.end(); ++iter)
{
m_Groups.insert(m_Groups.end(), CreateGroup(*iter));
}
return true;
}
return false;
}
bool Group::BelongsToGroup(const std::wstring& group) const
{
return (m_Groups.find(VerifyGroup(group)) != m_Groups.end());
}
std::wstring& Group::CreateGroup(std::wstring& str) const
{
_wcsupr(&str[0]);
return str;
}
std::wstring Group::VerifyGroup(const std::wstring& str) const
{
std::wstring strTmp;
std::wstring::size_type pos = str.find_first_not_of(L" \t\r\n");
if (pos != std::wstring::npos)
{
// Trim white-space
strTmp.assign(str, pos, str.find_last_not_of(L" \t\r\n") - pos + 1);
CreateGroup(strTmp);
}
return strTmp;
}