MCPcopy Create free account
hub / github.com/aethersdr/AetherSDR / parseRule

Function parseRule

src/core/NetRecurrence.cpp:141–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139} // namespace
140
141ParsedRule parseRule(const QString& rrule)
142{
143 ParsedRule rule;
144 const QStringList parts = rrule.trimmed().split(';', Qt::SkipEmptyParts);
145 QString byDay;
146
147 for (const QString& part : parts) {
148 const int eq = part.indexOf('=');
149 if (eq < 0)
150 continue;
151 const QString key = part.left(eq).trimmed().toUpper();
152 const QString val = part.mid(eq + 1).trimmed();
153
154 if (key == "FREQ") {
155 const QString f = val.toUpper();
156 if (f == "DAILY")
157 rule.freq = ParsedRule::Freq::Daily;
158 else if (f == "WEEKLY")
159 rule.freq = ParsedRule::Freq::Weekly;
160 else if (f == "MONTHLY")
161 rule.freq = ParsedRule::Freq::Monthly;
162 } else if (key == "INTERVAL") {
163 bool ok = false;
164 const int n = val.toInt(&ok);
165 if (ok && n > 0)
166 rule.interval = n;
167 } else if (key == "BYDAY") {
168 byDay = val;
169 }
170 }
171
172 if (!rule.isValid())
173 return rule;
174
175 if (rule.freq == ParsedRule::Freq::Monthly) {
176 // BYDAY for MONTHLY is a single ordinal weekday, e.g. "1SU" or "-1WE".
177 const QString token = byDay.trimmed().toUpper();
178 int idx = 0;
179 bool negative = false;
180 if (token.startsWith('-')) {
181 negative = true;
182 idx = 1;
183 } else if (token.startsWith('+')) {
184 idx = 1;
185 }
186 int digitsEnd = idx;
187 while (digitsEnd < token.size() && token.at(digitsEnd).isDigit())
188 ++digitsEnd;
189 if (digitsEnd > idx) {
190 int ord = token.mid(idx, digitsEnd - idx).toInt();
191 if (negative)
192 ord = -ord;
193 rule.monthlyOrdinal = ord;
194 rule.monthlyWeekday = weekdayFromCode(token.mid(digitsEnd));
195 }
196 if (rule.monthlyWeekday == 0 || rule.monthlyOrdinal == 0)
197 rule.freq = ParsedRule::Freq::Invalid;
198 return rule;

Callers 4

nextOccurrenceFunction · 0.85
describeRuleFunction · 0.85
loadRuleIntoControlsFunction · 0.85
mainFunction · 0.85

Calls 5

weekdayFromCodeFunction · 0.85
containsMethod · 0.80
isValidMethod · 0.45
sizeMethod · 0.45
isEmptyMethod · 0.45

Tested by 1

mainFunction · 0.68