File: tags.cpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (64 lines) | stat: -rw-r--r-- 2,141 bytes parent folder | download
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
#include "tags.hpp"

#include <components/fallback/fallback.hpp>

#include <MyGUI_Colour.h>

namespace Gui
{

    bool replaceTag(std::string_view tag, MyGUI::UString& out)
    {
        std::string_view fontcolour = "fontcolour=";

        std::string_view fontcolourhtml = "fontcolourhtml=";

        if (tag.starts_with(fontcolour))
        {
            std::string fallbackName = "FontColor_color_";
            fallbackName += tag.substr(fontcolour.length());
            std::string_view str = Fallback::Map::getString(fallbackName);
            if (str.empty())
                throw std::runtime_error("Unknown fallback name: " + fallbackName);

            std::string ret[3];
            unsigned int j = 0;
            for (unsigned int i = 0; i < str.length(); ++i)
            {
                if (str[i] == ',')
                    j++;
                else if (str[i] != ' ')
                    ret[j] += str[i];
            }
            MyGUI::Colour col(MyGUI::utility::parseInt(ret[0]) / 255.f, MyGUI::utility::parseInt(ret[1]) / 255.f,
                MyGUI::utility::parseInt(ret[2]) / 255.f);
            out = col.print();
            return true;
        }
        else if (tag.starts_with(fontcolourhtml))
        {
            std::string fallbackName = "FontColor_color_";
            fallbackName += tag.substr(fontcolourhtml.length());
            std::string_view str = Fallback::Map::getString(fallbackName);
            if (str.empty())
                throw std::runtime_error("Unknown fallback name: " + fallbackName);

            std::string ret[3];
            unsigned int j = 0;
            for (unsigned int i = 0; i < str.length(); ++i)
            {
                if (str[i] == ',')
                    j++;
                else if (str[i] != ' ')
                    ret[j] += str[i];
            }
            std::stringstream html;
            html << "#" << std::hex << MyGUI::utility::parseInt(ret[0]) << MyGUI::utility::parseInt(ret[1])
                 << MyGUI::utility::parseInt(ret[2]);
            out = html.str();
            return true;
        }
        return false;
    }

}