@@ -24,180 +24,117 @@ namespace flags
24
24
if (FlagArray[ulCurEntry].ulFlagName != ulFlagName) return L" " ;
25
25
26
26
// We've matched our flag name to the array - we SHOULD return a string at this point
27
- auto bNeedSeparator = false ;
28
-
27
+ auto flags = std::vector<std::wstring>{};
29
28
auto lTempValue = lFlagValue;
30
- std::wstring szTempString;
31
- for (; FlagArray[ulCurEntry].ulFlagName == ulFlagName; ulCurEntry++)
29
+ while (FlagArray[ulCurEntry].ulFlagName == ulFlagName)
32
30
{
33
- if (flagFLAG == FlagArray[ulCurEntry].ulFlagType )
31
+ switch ( FlagArray[ulCurEntry].ulFlagType )
34
32
{
33
+ case flagFLAG:
35
34
if (FlagArray[ulCurEntry].lFlagValue & lTempValue)
36
35
{
37
- if (bNeedSeparator)
38
- {
39
- szTempString += L" | " ; // STRING_OK
40
- }
41
-
42
- szTempString += FlagArray[ulCurEntry].lpszName ;
36
+ flags.push_back (FlagArray[ulCurEntry].lpszName );
43
37
lTempValue &= ~FlagArray[ulCurEntry].lFlagValue ;
44
- bNeedSeparator = true ;
45
38
}
46
- }
47
- else if (flagVALUE == FlagArray[ulCurEntry].ulFlagType )
48
- {
39
+ break ;
40
+ case flagVALUE:
49
41
if (FlagArray[ulCurEntry].lFlagValue == lTempValue)
50
42
{
51
- if (bNeedSeparator)
52
- {
53
- szTempString += L" | " ; // STRING_OK
54
- }
55
-
56
- szTempString += FlagArray[ulCurEntry].lpszName ;
43
+ flags.push_back (FlagArray[ulCurEntry].lpszName );
57
44
lTempValue = 0 ;
58
- bNeedSeparator = true ;
59
45
}
60
- }
61
- else if (flagVALUEHIGHBYTES == FlagArray[ulCurEntry].ulFlagType )
62
- {
46
+ break ;
47
+ case flagVALUEHIGHBYTES:
63
48
if (FlagArray[ulCurEntry].lFlagValue == (lTempValue >> 16 & 0xFFFF ))
64
49
{
65
- if (bNeedSeparator)
66
- {
67
- szTempString += L" | " ; // STRING_OK
68
- }
69
-
70
- szTempString += FlagArray[ulCurEntry].lpszName ;
50
+ flags.push_back (FlagArray[ulCurEntry].lpszName );
71
51
lTempValue = lTempValue - (FlagArray[ulCurEntry].lFlagValue << 16 );
72
- bNeedSeparator = true ;
73
52
}
74
- }
75
- else if (flagVALUE3RDBYTE == FlagArray[ulCurEntry].ulFlagType )
76
- {
53
+ break ;
54
+ case flagVALUE3RDBYTE:
77
55
if (FlagArray[ulCurEntry].lFlagValue == (lTempValue >> 8 & 0xFF ))
78
56
{
79
- if (bNeedSeparator)
80
- {
81
- szTempString += L" | " ; // STRING_OK
82
- }
83
-
84
- szTempString += FlagArray[ulCurEntry].lpszName ;
57
+ flags.push_back (FlagArray[ulCurEntry].lpszName );
85
58
lTempValue = lTempValue - (FlagArray[ulCurEntry].lFlagValue << 8 );
86
- bNeedSeparator = true ;
87
59
}
88
- }
89
- else if (flagVALUE4THBYTE == FlagArray[ulCurEntry].ulFlagType )
90
- {
60
+ break ;
61
+ case flagVALUE4THBYTE:
91
62
if (FlagArray[ulCurEntry].lFlagValue == (lTempValue & 0xFF ))
92
63
{
93
- if (bNeedSeparator)
94
- {
95
- szTempString += L" | " ; // STRING_OK
96
- }
97
-
98
- szTempString += FlagArray[ulCurEntry].lpszName ;
64
+ flags.push_back (FlagArray[ulCurEntry].lpszName );
99
65
lTempValue = lTempValue - FlagArray[ulCurEntry].lFlagValue ;
100
- bNeedSeparator = true ;
101
66
}
102
- }
103
- else if (flagVALUELOWERNIBBLE == FlagArray[ulCurEntry].ulFlagType )
104
- {
67
+ break ;
68
+ case flagVALUELOWERNIBBLE:
105
69
if (FlagArray[ulCurEntry].lFlagValue == (lTempValue & 0x0F ))
106
70
{
107
- if (bNeedSeparator)
108
- {
109
- szTempString += L" | " ; // STRING_OK
110
- }
111
-
112
- szTempString += FlagArray[ulCurEntry].lpszName ;
71
+ flags.push_back (FlagArray[ulCurEntry].lpszName );
113
72
lTempValue = lTempValue - FlagArray[ulCurEntry].lFlagValue ;
114
- bNeedSeparator = true ;
115
73
}
116
- }
117
- else if (flagCLEARBITS == FlagArray[ulCurEntry].ulFlagType )
118
- {
74
+ break ;
75
+ case flagCLEARBITS:
119
76
// find any bits we need to clear
120
77
const auto lClearedBits = FlagArray[ulCurEntry].lFlagValue & lTempValue;
121
78
// report what we found
122
- if (0 != lClearedBits )
79
+ if (lClearedBits != 0 )
123
80
{
124
- if (bNeedSeparator)
125
- {
126
- szTempString += L" | " ; // STRING_OK
127
- }
128
-
129
- szTempString += strings::format (L" 0x%X" , lClearedBits); // STRING_OK
81
+ flags.push_back (strings::format (L" 0x%X" , lClearedBits)); // STRING_OK
130
82
// clear the bits out
131
83
lTempValue &= ~FlagArray[ulCurEntry].lFlagValue ;
132
- bNeedSeparator = true ;
133
84
}
85
+ break ;
134
86
}
87
+
88
+ ulCurEntry++;
135
89
}
136
90
137
- // We know if we've found anything already because bNeedSeparator will be true
138
- // If bNeedSeparator isn't true, we found nothing and need to tack on
139
- // Otherwise, it's true, and we only tack if lTempValue still has something in it
140
- if (!bNeedSeparator || lTempValue)
91
+ if (lTempValue || flags.empty ())
141
92
{
142
- if (bNeedSeparator)
143
- {
144
- szTempString += L" | " ; // STRING_OK
145
- }
146
-
147
- szTempString += strings::format (L" 0x%X" , lTempValue); // STRING_OK
93
+ flags.push_back (strings::format (L" 0x%X" , lTempValue)); // STRING_OK
148
94
}
149
95
150
- return szTempString ;
96
+ return strings::join (flags, L" | " ) ;
151
97
}
152
98
153
99
// Returns a list of all known flags/values for a flag name.
154
100
// For instance, for flagFuzzyLevel, would return:
155
- // \r\n0x00000000 FL_FULLSTRING\r\n\
156
- // 0x00000001 FL_SUBSTRING\r\n\
157
- // 0x00000002 FL_PREFIX\r\n\
158
- // 0x00010000 FL_IGNORECASE\r\n\
159
- // 0x00020000 FL_IGNORENONSPACE\r\n\
160
- // 0x00040000 FL_LOOSE
101
+ // 0x00000000 FL_FULLSTRING\r\n\
102
+ // 0x00000001 FL_SUBSTRING\r\n\
103
+ // 0x00000002 FL_PREFIX\r\n\
104
+ // 0x00010000 FL_IGNORECASE\r\n\
105
+ // 0x00020000 FL_IGNORENONSPACE\r\n\
106
+ // 0x00040000 FL_LOOSE
161
107
//
162
108
// Since the string is always appended to a prompt we include \r\n at the start
163
109
std::wstring AllFlagsToString (ULONG ulFlagName, bool bHex)
164
110
{
165
- std::wstring szFlagString;
166
- if (!ulFlagName) return szFlagString;
167
- if (FlagArray.empty ()) return szFlagString;
111
+ if (!ulFlagName) return L" " ;
112
+ if (FlagArray.empty ()) return L" " ;
168
113
169
114
ULONG ulCurEntry = 0 ;
170
- std::wstring szTempString;
171
115
172
116
while (ulCurEntry < FlagArray.size () && FlagArray[ulCurEntry].ulFlagName != ulFlagName)
173
117
{
174
118
ulCurEntry++;
175
119
}
176
120
177
- if (FlagArray[ulCurEntry].ulFlagName != ulFlagName) return szFlagString ;
121
+ if (ulCurEntry == FlagArray. size () || FlagArray [ulCurEntry].ulFlagName != ulFlagName) return L" " ;
178
122
179
123
// We've matched our flag name to the array - we SHOULD return a string at this point
180
- for (; FlagArray[ulCurEntry].ulFlagName == ulFlagName; ulCurEntry++)
124
+ auto flags = std::vector<std::wstring>{};
125
+ while (FlagArray[ulCurEntry].ulFlagName == ulFlagName)
181
126
{
182
- if (flagCLEARBITS = = FlagArray[ulCurEntry].ulFlagType )
127
+ if (flagCLEARBITS ! = FlagArray[ulCurEntry].ulFlagType )
183
128
{
184
- // keep going
185
- }
186
- else
187
- {
188
- if (bHex)
189
- {
190
- szFlagString += strings::formatmessage (
191
- IDS_FLAGTOSTRINGHEX, FlagArray[ulCurEntry].lFlagValue , FlagArray[ulCurEntry].lpszName );
192
- }
193
- else
194
- {
195
- szFlagString += strings::formatmessage (
196
- IDS_FLAGTOSTRINGDEC, FlagArray[ulCurEntry].lFlagValue , FlagArray[ulCurEntry].lpszName );
197
- }
129
+ flags.push_back (strings::formatmessage (
130
+ bHex ? IDS_FLAGTOSTRINGHEX : IDS_FLAGTOSTRINGDEC,
131
+ FlagArray[ulCurEntry].lFlagValue ,
132
+ FlagArray[ulCurEntry].lpszName ));
198
133
}
134
+
135
+ ulCurEntry++;
199
136
}
200
137
201
- return szFlagString ;
138
+ return strings::join (flags, L" \r\n " ) ;
202
139
}
203
140
} // namespace flags
0 commit comments