Repository: xbmc/xbmc
File: xbmc/guilib/GUIIncludes.cpp (C++)

Code before:
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "GUIIncludes.h"

#include "GUIInfoManager.h"
#include "addons/Skin.h"
#include "guilib/GUIComponent.h"
#include "guilib/guiinfo/GUIInfoLabel.h"
#include "interfaces/info/SkinVariable.h"
#include "utils/StringUtils.h"
#include "utils/XBMCTinyXML.h"
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <algorithm>

using namespace KODI::GUILIB;

static constexpr std::array<std::string_view, 17> constantAttributes = {
    "x",     "y",   "width",  "height", "center",       "max",
    "min",   "w",   "h",      "time",   "acceleration", "delay",
    "start", "end", "center", "border", "repeat",
};

static constexpr std::array<std::string_view, 35> constantNodes = {
    "posx",        "posy",        "left",         "centerleft",   "right",         "centerright",
    "top",         "centertop",   "bottom",       "centerbottom", "width",         "height",
    "offsetx",     "offsety",     "textoffsetx",  "textoffsety",  "textwidth",     "spinposx",
    "spinposy",    "spinwidth",   "spinheight",   "radioposx",    "radioposy",     "radiowidth",
    "radioheight", "sliderwidth", "sliderheight", "itemgap",      "bordersize",    "timeperimage",
    "fadetime",    "pauseatend",  "depth",        "movement",     "focusposition",
};

static constexpr std::array<std::string_view, 1> expressionAttributes = {
    "condition",
};

static constexpr std::array<std::string_view, 4> expressionNodes = {
    "visible",
    "enable",
    "usealttexture",
    "selected",
};

CGUIIncludes::CGUIIncludes() = default;

CGUIIncludes::~CGUIIncludes() = default;

Review comment (suggestion):
I'm not opposed to switch to `std::array`, but I think using the `std::range::find` in the checks hurts readability a little. I suggest to add a small function that makes the intention clearer:
```cpp
static constexpr std::array<std::string_view, 17> CONSTANT_ATTRIBUTES = {
    "x",     "y",   "width",  "height", "center",       "max",
    "min",   "w",   "h",      "time",   "acceleration", "delay",
    "start", "end", "center", "border", "repeat",
};
static constexpr bool IsConstantAttribtute(const TiXmlAttribute& attribute)
{
  return std::ranges::find(CONSTANT_ATTRIBUTES, attribute.Name()) != CONSTANT_ATTRIBUTES.end();
}
```

Same for the other arrays below.

Code after:
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "GUIIncludes.h"

#include "GUIInfoManager.h"
#include "addons/Skin.h"
#include "guilib/GUIComponent.h"
#include "guilib/guiinfo/GUIInfoLabel.h"
#include "interfaces/info/SkinVariable.h"
#include "utils/StringUtils.h"
#include "utils/XBMCTinyXML.h"
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <algorithm>

using namespace KODI::GUILIB;

static constexpr std::array<std::string_view, 16> CONSTANT_ATTRIBUTES = {
    "acceleration", "border", "center", "delay", "end", "h",     "height", "max",
    "min",          "repeat", "start",  "time",  "w",   "width", "x",      "y",
};
static_assert(std::ranges::is_sorted(CONSTANT_ATTRIBUTES));

static constexpr std::array<std::string_view, 35> CONSTANT_NODES = {
    "bordersize",  "bottom",     "centerbottom",  "centerleft", "centerright", "centertop",
    "depth",       "fadetime",   "focusposition", "height",     "itemgap",     "left",
    "movement",    "offsetx",    "offsety",       "pauseatend", "posx",        "posy",
    "radioheight", "radioposx",  "radioposy",     "radiowidth", "right",       "sliderheight",
    "sliderwidth", "spinheight", "spinposx",      "spinposy",   "spinwidth",   "textoffsetx",
    "textoffsety", "textwidth",  "timeperimage",  "top",        "width",
};
static_assert(std::ranges::is_sorted(CONSTANT_NODES));

static constexpr std::string_view EXPRESSION_ATTRIBUTE = "condition";

static constexpr std::array<std::string_view, 4> EXPRESSION_NODES = {
    "enable",
    "selected",
    "usealttexture",
    "visible",
};
static_assert(std::ranges::is_sorted(EXPRESSION_NODES));

CGUIIncludes::CGUIIncludes() = default;

CGUIIncludes::~CGUIIncludes() = default;