xoreos  0.0.5
tokenman.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 
28 
29 namespace Engines {
30 
32 }
33 
35 }
36 
38  _tokens.clear();
39 }
40 
41 void TokenManager::set(const Common::UString &token, const Common::UString &value) {
42  _tokens[token] = value;
43 }
44 
46  TokenMap::iterator t = _tokens.find(token);
47  if (t == _tokens.end())
48  return;
49 
50  _tokens.erase(t);
51 }
52 
54  Common::UString parsed = parse((const Common::UString &) str);
55 
56  str.swap(parsed);
57 }
58 
60  Common::UString parsed;
61 
62  std::vector<Common::UString> tokens;
64 
65  bool plain = true;
66  for (std::vector<Common::UString>::iterator t = tokens.begin(); t != tokens.end(); ++t) {
67 
68  if (!plain) {
69  TokenMap::const_iterator token = _tokens.find(*t);
70 
71  parsed += (token == _tokens.end()) ? *t : token->second;
72  } else
73  parsed += *t;
74 
75  plain = !plain;
76  }
77 
78  return parsed;
79 }
80 
81 } // End of namespace Engines
A class holding an UTF-8 string.
Definition: ustring.h:48
void swap(UString &str)
Swap the contents of the string with this string&#39;s.
Definition: ustring.cpp:230
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
Definition: singleton.h:122
static void splitTextTokens(const UString &text, std::vector< UString > &tokens)
Definition: ustring.cpp:645
void remove(const Common::UString &token)
Remove the value of a token.
Definition: tokenman.cpp:45
void set(const Common::UString &token, const Common::UString &value)
Set a value for a token.
Definition: tokenman.cpp:41
Manager for tokens in Aurora engines text strings.
void parse(Common::UString &str) const
Parse a string for tokens, replacing them with their values.
Definition: tokenman.cpp:53
Manager for tokens in Aurora engines text strings.
Definition: tokenman.h:36
void clear()
Clear all tokens.
Definition: tokenman.cpp:37