11#include " CodeService/Config/LuaStyle.h"
22#include < map>
3- #include < regex >
3+ #include " FunctionOption.h "
44
55bool IsNumber (std::string_view source) {
66 for (auto c: source) {
@@ -159,7 +159,7 @@ void LuaStyle::ParseFromMap(std::map<std::string, std::string, std::less<>> &con
159159
160160 BOOL_OPTION (never_indent_before_if_condition)
161161
162- if (align_if_branch){
162+ if (align_if_branch) {
163163 never_indent_before_if_condition = true ;
164164 }
165165
@@ -176,30 +176,33 @@ void LuaStyle::ParseFromMap(std::map<std::string, std::string, std::less<>> &con
176176 {" line_space_after_expression_statement" , line_space_after_expression_statement},
177177 {" line_space_after_comment" , line_space_after_comment}
178178 };
179- std::regex minLineRegex = std::regex (R"( minLine:\s*(\d+))" );
180- std::regex keepLineRegex = std::regex (R"( keepLine:\s*(\d+))" );
181- std::regex maxLineRegex = std::regex (R"( maxLine:\s*(\d+))" );
182- for (auto &keepLineOption: fieldList) {
183- if (configMap.count (keepLineOption.first )) {
184- std::string value = configMap.at (keepLineOption.first );
185- if (value == " keepLine" ) {
186- keepLineOption.second = LineSpace (LineSpaceType::Keep);
187- continue ;
188- }
189- std::smatch m;
190179
191- if (std::regex_search (value, m, minLineRegex)) {
192- keepLineOption.second = LineSpace (LineSpaceType::Min, std::stoi (m.str (1 )));
193- continue ;
194- }
180+ for (auto &lineOption: fieldList) {
181+ if (configMap.count (lineOption.first )) {
182+ std::string value = configMap.at (lineOption.first );
183+ FunctionOption option;
184+ option.Parse (value);
195185
196- if (std::regex_search (value, m, keepLineRegex)) {
197- keepLineOption.second = LineSpace (LineSpaceType::Fixed, std::stoi (m.str (1 )));
198- continue ;
186+ if (option.GetKey () == " keep" ) {
187+ lineOption.second = LineSpace (LineSpaceType::Keep);
199188 }
200-
201- if (std::regex_search (value, m, maxLineRegex)) {
202- keepLineOption.second = LineSpace (LineSpaceType::Max, std::stoi (m.str (1 )));
189+ else if (option.GetKey () == " min" ) {
190+ auto p1 = option.GetParam (0 );
191+ if (!p1.empty () && IsNumber (p1)) {
192+ lineOption.second = LineSpace (LineSpaceType::Min, std::stoi (p1));
193+ }
194+ }
195+ else if (option.GetKey () == " fixed" ) {
196+ auto p1 = option.GetParam (0 );
197+ if (!p1.empty () && IsNumber (p1)) {
198+ lineOption.second = LineSpace (LineSpaceType::Fixed, std::stoi (p1));
199+ }
200+ }
201+ else if (option.GetKey () == " max" ) {
202+ auto p1 = option.GetParam (0 );
203+ if (!p1.empty () && IsNumber (p1)) {
204+ lineOption.second = LineSpace (LineSpaceType::Max, std::stoi (p1));
205+ }
203206 }
204207 }
205208 }
0 commit comments