MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / WriteSyntaxNode

Method WriteSyntaxNode

CodeFormatCore/src/Format/FormatBuilder.cpp:27–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27void FormatBuilder::WriteSyntaxNode(LuaSyntaxNode &syntaxNode, const LuaSyntaxTree &t) {
28 auto text = syntaxNode.GetText(t);
29
30 switch (syntaxNode.GetTokenKind(t)) {
31 case TK_STRING:
32 case TK_LONG_STRING:
33 case TK_LONG_COMMENT: {
34 WriteText(text);
35 break;
36 }
37 case TK_NUMBER: {
38 // Remove leading zero in floats between 0 and 1 if enabled
39 const auto &style = _state.GetStyle();
40 if (style.remove_leading_zero_in_float) {
41 // Handle positive and negative numbers
42 if (text.size() > 1 && text[0] == '0' && text[1] == '.') {
43 // 0.xxx -> .xxx
44 _state.CurrentWidth() += utf8::Utf8nLen(text.data() + 1, text.size() - 1);
45 _formattedText.append(text.substr(1));
46 break;
47 } else if (text.size() > 2 && text[0] == '-' && text[1] == '0' && text[2] == '.') {
48 // -0.xxx -> -.xxx
49 _state.CurrentWidth() += utf8::Utf8nLen(text.data(), 1); // '-'
50 _state.CurrentWidth() += utf8::Utf8nLen(text.data() + 2, text.size() - 2);
51 _formattedText.push_back('-');
52 _formattedText.append(text.substr(2));
53 break;
54 }
55 }
56 // Default behavior
57 _state.CurrentWidth() += syntaxNode.GetUtf8Length(t);
58 _formattedText.append(text);
59 break;
60 }
61 default: {
62 _state.CurrentWidth() += syntaxNode.GetUtf8Length(t);
63 _formattedText.append(text);
64 }
65 }
66}
67
68void FormatBuilder::DoResolve(LuaSyntaxNode &syntaxNode, const LuaSyntaxTree &t, FormatResolve &resolve) {
69 if (syntaxNode.IsToken(t)) {

Callers

nothing calls this directly

Calls 7

GetTextMethod · 0.80
GetStyleMethod · 0.80
GetUtf8LengthMethod · 0.80
GetTokenKindMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected