|
4 | 4 |
|
5 | 5 | CommandParameter::CommandParameter(QObject *parent, QString i_argString) : QObject(parent), m_string(i_argString)
|
6 | 6 | {
|
7 |
| - isRequired = false; |
8 |
| - isOptional = false; |
9 |
| - isLong = false; |
10 |
| - isVarArg = false; |
11 |
| - isSwitch = false; |
12 |
| - parse(); |
| 7 | + isRequired = false; |
| 8 | + isOptional = false; |
| 9 | + isLong = false; |
| 10 | + isVarArg = false; |
| 11 | + isSwitch = false; |
| 12 | + isRequiredLong = false; |
| 13 | + parse(); |
13 | 14 | }
|
14 | 15 |
|
15 | 16 | QStringList CommandParameter::find_captures(QString regexString)
|
16 | 17 | {
|
17 |
| - QRegExp rx(regexString); |
| 18 | + QRegExp rx(regexString); |
18 | 19 |
|
19 |
| - QStringList list; |
20 |
| - int pos = 0; |
| 20 | + QStringList list; |
| 21 | + int pos = 0; |
21 | 22 |
|
22 |
| - while ((pos = rx.indexIn(m_string, pos)) != -1) { |
23 |
| - list << rx.cap(1); |
24 |
| - pos += rx.matchedLength(); |
| 23 | + while ((pos = rx.indexIn(m_string, pos)) != -1) { |
| 24 | + list << rx.cap(1); |
| 25 | + pos += rx.matchedLength(); |
25 | 26 | }
|
26 |
| - return list; |
| 27 | + return list; |
27 | 28 | }
|
28 | 29 |
|
29 | 30 | QString CommandParameter::html()
|
30 | 31 | {
|
31 |
| - QString rv; |
32 |
| - if (isRequired) { |
33 |
| - rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-red wp-parameter' required>").arg(parameterIndex); |
| 32 | + QString rv; |
| 33 | + |
| 34 | + if (isRequired) { |
| 35 | + rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-red wp-parameter' required>").arg(parameterIndex); |
| 36 | + } |
| 37 | + if (isOptional) { |
| 38 | + rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-blue wp-parameter'>").arg(parameterIndex); |
34 | 39 | }
|
35 |
| - if (isOptional) { |
36 |
| - rv = QString("<input type='text' name='%1' class='w3-input w3-rest w3-border-blue wp-parameter'>").arg(parameterIndex); |
| 40 | + |
| 41 | + if (isSwitch) { |
| 42 | + rv = QString("<input type='checkbox' name='%1' class='w3-checkbox w3-rest w3-large wp-parameter'>").arg(parameterIndex); |
37 | 43 | }
|
38 |
| - if (isSwitch) { |
39 |
| - rv = QString("<input type='checkbox' name='%1' class='w3-checkbox w3-rest w3-large wp-parameter'>").arg(parameterIndex); |
| 44 | + if (isLong) { |
| 45 | + flagValue.remove("&"); |
| 46 | + flagValue.remove(">"); |
| 47 | + flagValue.remove("<"); |
| 48 | + flagValue.remove("--"); |
| 49 | + flagValue.remove("\""); |
| 50 | + flagValue.remove("["); |
| 51 | + flagValue.remove("]"); |
| 52 | + flagValue.remove("}"); |
| 53 | + flagValue.remove("{"); |
| 54 | + flagValue.remove("\\n"); |
| 55 | + flagValue.remove(" "); |
| 56 | + flagValue.remove(QChar(QChar::LineFeed)); |
| 57 | + flagValue.remove(QChar(QChar::CarriageReturn)); |
| 58 | + flagValue.remove(QChar(QChar::LineSeparator)); |
| 59 | + |
| 60 | + rv = QString("<input type='text' name='%1' class=' w3-input w3-rest w3-large wp-parameter' placeholder='%2'>").arg(parameterIndex).arg(flagValue); |
40 | 61 | }
|
41 |
| - if (isLong) { |
42 |
| - flagValue.remove("&"); |
43 |
| - flagValue.remove(">"); |
44 |
| - flagValue.remove("<"); |
45 |
| - flagValue.remove("--"); |
46 |
| - flagValue.remove("\""); |
47 |
| - flagValue.remove("["); |
48 |
| - flagValue.remove("]"); |
49 |
| - flagValue.remove("}"); |
50 |
| - flagValue.remove("{"); |
51 |
| - flagValue.remove("\\n"); |
52 |
| - flagValue.remove(" "); |
53 |
| - flagValue.remove(QChar(QChar::LineFeed)); |
54 |
| - flagValue.remove(QChar(QChar::CarriageReturn)); |
55 |
| - flagValue.remove(QChar(QChar::LineSeparator)); |
56 |
| - |
57 |
| - rv = QString("<input type='text' name='%1' class=' w3-input w3-rest w3-large wp-parameter' placeholder='%2'>").arg(parameterIndex).arg(flagValue); |
| 62 | + |
| 63 | + if (isRequiredLong) { |
| 64 | + flagValue.remove("&"); |
| 65 | + flagValue.remove(">"); |
| 66 | + flagValue.remove("<"); |
| 67 | + flagValue.remove("--"); |
| 68 | + flagValue.remove("\""); |
| 69 | + flagValue.remove("["); |
| 70 | + flagValue.remove("]"); |
| 71 | + flagValue.remove("}"); |
| 72 | + flagValue.remove("{"); |
| 73 | + flagValue.remove("\\n"); |
| 74 | + flagValue.remove(" "); |
| 75 | + flagValue.remove(QChar(QChar::LineFeed)); |
| 76 | + flagValue.remove(QChar(QChar::CarriageReturn)); |
| 77 | + flagValue.remove(QChar(QChar::LineSeparator)); |
| 78 | + |
| 79 | + rv = QString("<input type='text' name='%1' class=' w3-input w3-rest w3-large wp-parameter' placeholder='%2' required>").arg(parameterIndex).arg(flagValue); |
58 | 80 | }
|
59 | 81 |
|
60 |
| - return rv; |
| 82 | + return rv; |
61 | 83 |
|
62 | 84 | }
|
63 | 85 |
|
64 | 86 | QString CommandParameter::toString()
|
65 | 87 | {
|
66 |
| - QString rv; |
67 |
| - if ((isOptional == true) || (isRequired == true)) { |
| 88 | + QString rv; |
| 89 | + if (isRequiredLong == true) { |
| 90 | + if (parameterValue.toString().length() > 0) { |
| 91 | + return QString("--%1=%2").arg(flagProperty).arg(parameterValue.toString()); |
| 92 | + } else { |
| 93 | + return ""; |
| 94 | + } |
| 95 | + } |
68 | 96 |
|
69 |
| - return this->parameterValue.toString(); |
| 97 | + if ((isOptional == true) || (isRequired == true)) { |
| 98 | + |
| 99 | + return this->parameterValue.toString(); |
70 | 100 |
|
71 | 101 | }
|
72 |
| - if (isSwitch == true) { |
73 |
| - if (this->parameterValue.toBool() == true) { |
74 |
| - return QString("--%1").arg(this->flagProperty); |
| 102 | + |
| 103 | + if (isSwitch == true) { |
| 104 | + if (this->parameterValue.toBool() == true) { |
| 105 | + return QString("--%1").arg(this->flagProperty); |
75 | 106 | } else {
|
76 |
| - return " "; |
| 107 | + return " "; |
77 | 108 | }
|
78 | 109 | }
|
79 |
| - if (isLong == true) { |
80 |
| - if (parameterValue.toString().length() > 0) { |
81 |
| - return QString("--%1=%2").arg(flagProperty).arg(parameterValue.toString()); |
| 110 | + if (isLong == true) { |
| 111 | + if (parameterValue.toString().length() > 0) { |
| 112 | + return QString("--%1=%2").arg(flagProperty).arg(parameterValue.toString()); |
82 | 113 | } else {
|
83 |
| - return ""; |
| 114 | + return ""; |
84 | 115 | }
|
85 | 116 | }
|
86 | 117 |
|
87 |
| - return " "; |
| 118 | + return " "; |
88 | 119 | }
|
89 | 120 |
|
90 | 121 | void CommandParameter::parse()
|
91 | 122 | {
|
92 |
| - QStringList optionalFlags; |
93 |
| - optionalFlags << this->find_captures("(\\[\\-\\-\\S+\\=<\\S+\\>\\]\\B)"); |
94 |
| - if (optionalFlags.count() == 0) { |
95 |
| - QStringList required; |
96 |
| - |
97 |
| - required << this->find_captures("(\\<\\S+\\>\\B)"); |
98 |
| - if (required.count() == 0) { |
99 |
| - QStringList optional; |
100 |
| - optional << this->find_captures("(\\[\\[^\\>\\<]+\\]\\B)"); |
101 |
| - if (optional.count() == 0) { |
102 |
| - // qDebug() << "Switch" << m_string; |
103 |
| - |
104 |
| - isSwitch = true; |
105 |
| - flagProperty = m_string; |
106 |
| - if (flagProperty.length() > 2) { |
107 |
| - flagProperty.remove(0, 3); |
| 123 | + QStringList requiredFlags; |
| 124 | + requiredFlags << this->find_captures("(\\-\\-\\S+\\=<\\S+\\>\\B)"); |
| 125 | + if (requiredFlags.count() == 0) { |
| 126 | + QStringList optionalFlags; |
| 127 | + optionalFlags << this->find_captures("(\\[\\-\\-\\S+\\=<\\S+\\>\\]\\B)"); |
| 128 | + if (optionalFlags.count() == 0) { |
| 129 | + QStringList required; |
| 130 | + |
| 131 | + required << this->find_captures("(\\<\\S+\\>\\B)"); |
| 132 | + if (required.count() == 0) { |
| 133 | + QStringList optional; |
| 134 | + optional << this->find_captures("(\\[\\[^\\>\\<]+\\]\\B)"); |
| 135 | + if (optional.count() == 0) { |
| 136 | + qDebug() << "Switch" << m_string; |
| 137 | + |
| 138 | + isSwitch = true; |
| 139 | + flagProperty = m_string; |
| 140 | + if (flagProperty.length() > 2) { |
| 141 | + flagProperty.remove(0, 3); |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + } else { |
| 146 | + qDebug() << "optional" << optional.first(); |
| 147 | + isOptional = true; |
| 148 | + m_string = optional.first(); |
| 149 | + flagProperty = ""; |
108 | 150 | }
|
109 |
| - |
110 |
| - |
111 | 151 | } else {
|
112 |
| - // qDebug() << "optional" << optional.first(); |
113 |
| - isOptional = true; |
114 |
| - m_string = optional.first(); |
115 |
| - flagProperty = ""; |
| 152 | + qDebug() << "requiured" << required.first(); |
| 153 | + isRequired = true; |
| 154 | + m_string = required.first(); |
| 155 | + flagProperty = ""; |
116 | 156 | }
|
117 | 157 | } else {
|
118 |
| - // qDebug() << "requiured" << required.first(); |
119 |
| - isRequired = true; |
120 |
| - m_string = required.first(); |
121 |
| - flagProperty = ""; |
| 158 | + qDebug() << "optional flag" << optionalFlags.first(); |
| 159 | + m_string = optionalFlags.first(); |
| 160 | + flagProperty = m_string.split("=").first(); |
| 161 | + if (flagProperty.length() > 3) { |
| 162 | + flagProperty.remove(0, 3); |
| 163 | + } |
| 164 | + flagValue = m_string.split("=").last(); |
| 165 | + isLong = true; |
122 | 166 | }
|
123 | 167 | } else {
|
124 |
| - // qDebug() << "optional flag" << optionalFlags.first(); |
125 |
| - m_string = optionalFlags.first(); |
126 |
| - flagProperty = m_string.split("=").first(); |
127 |
| - if (flagProperty.length() > 3) { |
128 |
| - flagProperty.remove(0, 3); |
| 168 | + qDebug() << "required flag" << requiredFlags.first(); |
| 169 | + m_string = requiredFlags.first(); |
| 170 | + flagProperty = m_string.split("=").first(); |
| 171 | + if (flagProperty.length() > 3) { |
| 172 | + flagProperty.remove(0, 2); |
129 | 173 | }
|
130 |
| - flagValue = m_string.split("=").last(); |
131 |
| - isLong = true; |
132 |
| - } |
| 174 | + flagValue = m_string.split("=").last(); |
| 175 | + isRequiredLong = true; |
133 | 176 |
|
| 177 | + } |
134 | 178 | }
|
135 | 179 |
|
136 | 180 | void CommandParameter::set_value(QVariant val)
|
137 | 181 | {
|
138 |
| - this->parameterValue = val; |
| 182 | + this->parameterValue = val; |
139 | 183 | }
|
0 commit comments