The Battle for Wesnoth  1.15.0-dev
old_markup.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 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 #include "deprecation.hpp"
17 #include "version.hpp"
18 
19 namespace gui2
20 {
21 
22 legacy_menu_item::legacy_menu_item(const std::string& str, const std::string deprecation_msg)
23  : icon_(), label_(str), desc_(), default_(false), contained_markup_(false)
24 {
25  if(label_.empty()) {
26  return;
27  }
28 
29  // Handle selection.
30  if(label_[0] == '*') {
31  default_ = true;
32  label_.erase(0, 1);
33  contained_markup_ = true;
34  }
35 
36  // Handle the special case with an image.
37  // 99.9% of uses put the image in the first column, so we ignore the slim possibility of it going in a different column
38  std::string::size_type pos = label_.find('=');
39  if(pos != std::string::npos && (label_[0] == '&' || pos == 0)) {
40  if(pos)
41  icon_ = label_.substr(1, pos - 1);
42  label_.erase(0, pos + 1);
43  contained_markup_ = true;
44  }
45 
46  // Search for an '=' symbol that is not inside markup.
47  std::string::size_type prev = 0;
48  bool open = false;
49  while((pos = label_.find('=', prev)) != std::string::npos) {
50  for(std::string::size_type i = prev; i != pos; ++i) {
51  switch(label_[i]) {
52  case '<':
53  open = true;
54  break;
55  case '>':
56  open = false;
57  break;
58  }
59  }
60  if(!open)
61  break;
62  prev = pos + 1;
63  }
64  if(pos != std::string::npos) {
65  desc_ = label_.substr(pos + 1);
66  label_.erase(pos);
67  contained_markup_ = true;
68  }
69 
70  if(contained_markup_) {
71  deprecated_message("Legacy DescriptionWML markup (&img=col1=col2)", DEP_LEVEL::FOR_REMOVAL, {1, 15, 0}, deprecation_msg);
72  }
73 }
74 }
std::string label_
The first text item of the menu item, normally a short string.
Definition: old_markup.hpp:85
legacy_menu_item(const std::string &str="", const std::string deprecation_msg="")
Definition: old_markup.cpp:22
bool contained_markup_
Was any old markup actually parsed?
Definition: old_markup.hpp:100
std::string desc_
The second text item of the menu item, normally a longer string.
Definition: old_markup.hpp:88
Generic file dialog.
Definition: field-fwd.hpp:22
std::string icon_
The icon for the menu item.
Definition: old_markup.hpp:82
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
Definition: deprecation.cpp:29
bool default_
Is the item the default item and thus initially selected.
Definition: old_markup.hpp:95
std::size_t i
Definition: function.cpp:933
map_location prev
Definition: astarsearch.cpp:64
Interfaces for manipulating version numbers of engine, add-ons, etc.