The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
old_markup.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2017 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program 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; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
17 namespace gui2
18 {
19 
21  : icon_(), label_(str), desc_(), default_(false)
22 {
23  if(label_.empty()) {
24  return;
25  }
26 
27  // Handle selection.
28  if(label_[0] == '*') {
29  default_ = true;
30  label_.erase(0, 1);
31  }
32 
33  // Handle the special case with an image.
34  std::string::size_type pos = label_.find('=');
35  if(pos != std::string::npos && (label_[0] == '&' || pos == 0)) {
36  if(pos)
37  icon_ = label_.substr(1, pos - 1);
38  label_.erase(0, pos + 1);
39  }
40 
41  // Search for an '=' symbol that is not inside markup.
42  std::string::size_type prev = 0;
43  bool open = false;
44  while((pos = label_.find('=', prev)) != std::string::npos) {
45  for(std::string::size_type i = prev; i != pos; ++i) {
46  switch(label_[i]) {
47  case '<':
48  open = true;
49  break;
50  case '>':
51  open = false;
52  break;
53  }
54  }
55  if(!open)
56  break;
57  prev = pos + 1;
58  }
59  if(pos != std::string::npos) {
60  desc_ = label_.substr(pos + 1);
61  label_.erase(pos);
62  }
63 }
64 }
std::vector< char_t > string
std::string label_
The first text item of the menu item, normally a short string.
Definition: old_markup.hpp:79
std::string desc_
The second text item of the menu item, normally a longer string.
Definition: old_markup.hpp:82
Generic file dialog.
Definition: field-fwd.hpp:22
std::string icon_
The icon for the menu item.
Definition: old_markup.hpp:76
legacy_menu_item(const std::string &str=std::string())
Definition: old_markup.cpp:20
bool default_
Is the item the default item and thus initially selected.
Definition: old_markup.hpp:89
size_t i
Definition: function.cpp:933
map_location prev
Definition: astarsearch.cpp:65