26 {
27 fTabs = 0;
28 fFreshline = true;
29
30
31
32 fInParseUntilNewline = false;
33 fInParseUntil = false;
34
35 int parensDepth = 0;
36
37
38 fIndex = 0;
39 fLength = string.length();
40 fInput = string.c_str();
41
42 while (fLength > fIndex) {
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 if (fInParseUntilNewline) {
73 this->parseUntilNewline();
74 continue;
75 }
76 if (fInParseUntil) {
77 this->parseUntil(fInParseUntilToken);
78 continue;
79 }
80 if (this->hasToken("#") || this->hasToken("//")) {
81 this->parseUntilNewline();
82 continue;
83 }
84 if (this->hasToken("/*")) {
85 this->parseUntil("*/");
86 continue;
87 }
88 if (fInput[fIndex] == '{') {
89 this->newline();
90 this->appendChar('{');
91 fTabs++;
92 this->newline();
93 continue;
94 }
95 if (fInput[fIndex] == '}') {
96 fTabs--;
97 this->newline();
98 this->appendChar('}');
99 this->newline();
100 continue;
101 }
102 if (fFreshline && fInput[fIndex] == ';') {
103 this->undoNewlineAfter('}');
104 this->appendChar(fInput[fIndex]);
105 this->newline();
106 continue;
107 }
108 if (fFreshline && fInput[fIndex] == ',') {
109 this->undoNewlineAfter('}');
110 this->appendChar(fInput[fIndex]);
111 continue;
112 }
113 if (this->hasToken(")")) {
114 parensDepth--;
115 continue;
116 }
117 if (this->hasToken("(")) {
118 parensDepth++;
119 continue;
120 }
121 if (this->hasToken(")")) {
122 parensDepth--;
123 continue;
124 }
125 if (!parensDepth && this->hasToken(";")) {
126 this->newline();
127 continue;
128 }
129 if (fInput[fIndex] == '\t' || fInput[fIndex] == '\n' ||
130 (fFreshline && fInput[fIndex] == ' ')) {
131 fIndex++;
132 continue;
133 }
134
135 this->appendChar(fInput[fIndex]);
136 }
137
138 return fPretty;
139 }