MCPcopy Create free account
hub / github.com/axmolengine/axmol / RectFromString

Function RectFromString

core/base/NS.cpp:102–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100// implement the functions
101
102Rect RectFromString(std::string_view str)
103{
104 Rect result = Rect::ZERO;
105
106 do
107 {
108 AX_BREAK_IF(str.empty());
109 auto content = str;
110
111 // find the first '{' and the third '}'
112 size_t nPosLeft = content.find('{');
113 size_t nPosRight = content.find('}');
114 for (int i = 1; i < 3; ++i)
115 {
116 if (nPosRight == std::string::npos)
117 {
118 break;
119 }
120 nPosRight = content.find('}', nPosRight + 1);
121 }
122 AX_BREAK_IF(nPosLeft == std::string::npos || nPosRight == std::string::npos);
123
124 content = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1);
125 size_t nPointEnd = content.find('}');
126 AX_BREAK_IF(nPointEnd == std::string::npos);
127 nPointEnd = content.find(',', nPointEnd);
128 AX_BREAK_IF(nPointEnd == std::string::npos);
129
130 // get the point string and size string
131 auto pointStr = content.substr(0, nPointEnd);
132 auto sizeStr = content.substr(nPointEnd + 1, content.length() - nPointEnd);
133
134 // split the string with ','
135 strArray pointInfo;
136 AX_BREAK_IF(!splitWithForm(pointStr, pointInfo));
137 strArray sizeInfo;
138 AX_BREAK_IF(!splitWithForm(sizeStr, sizeInfo));
139
140 float x = (float)utils::atof(pointInfo[0].c_str());
141 float y = (float)utils::atof(pointInfo[1].c_str());
142 float width = (float)utils::atof(sizeInfo[0].c_str());
143 float height = (float)utils::atof(sizeInfo[1].c_str());
144
145 result = Rect(x, y, width, height);
146 } while (0);
147
148 return result;
149}
150
151Vec2 PointFromString(std::string_view str)
152{

Calls 8

splitWithFormFunction · 0.85
atofFunction · 0.85
RectFunction · 0.50
emptyMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected