| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 1 | //===-- MICmdArgValString.cpp -----------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 10 | // In-house headers: |
| 11 | #include "MICmdArgValString.h" |
| 12 | #include "MICmdArgContext.h" |
| 13 | |
| 14 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 15 | // Details: CMICmdArgValString constructor. |
| 16 | // Type: Method. |
| 17 | // Args: None. |
| 18 | // Return: None. |
| 19 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 20 | //-- |
| Bruce Mitchener | e2453af | 2015-08-04 10:24:20 +0000 | [diff] [blame] | 21 | CMICmdArgValString::CMICmdArgValString() |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 22 | : m_bHandleQuotedString(false) |
| 23 | , m_bAcceptNumbers(false) |
| 24 | , m_bHandleDirPaths(false) |
| 25 | , m_bHandleAnything(false) |
| Deepak Panickal | f92dc58 | 2014-08-14 16:40:15 +0000 | [diff] [blame] | 26 | { |
| 27 | } |
| 28 | |
| 29 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 30 | // Details: CMICmdArgValString constructor. |
| 31 | // Type: Method. |
| 32 | // Args: vbAnything - (R) True = Parse a string and accept anything, false = do not accept anything. |
| 33 | // Return: None. |
| 34 | // Throws: None. |
| Deepak Panickal | f92dc58 | 2014-08-14 16:40:15 +0000 | [diff] [blame] | 35 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 36 | CMICmdArgValString::CMICmdArgValString(const bool vbAnything) |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 37 | : m_bHandleQuotedString(vbAnything ? true : false) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 38 | , m_bAcceptNumbers(false) |
| 39 | , m_bHandleDirPaths(false) |
| 40 | , m_bHandleAnything(vbAnything) |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
| 44 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 45 | // Details: CMICmdArgValString constructor. |
| 46 | // Type: Method. |
| Bruce Mitchener | d0ee89d | 2015-07-03 14:09:56 +0000 | [diff] [blame] | 47 | // Args: vbHandleQuotes - (R) True = Parse a string surrounded by quotes spaces are not delimiters, false = only text up to |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 48 | // next delimiting space character. |
| 49 | // vbAcceptNumbers - (R) True = Parse a string and accept as a number if number, false = numbers not recognised |
| 50 | // as string types. |
| 51 | // vbHandleDirPaths - (R) True = Parse a string and accept as a file path if a path, false = file paths are not |
| 52 | // recognised as string types. |
| 53 | // Return: None. |
| 54 | // Throws: None. |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 55 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 56 | CMICmdArgValString::CMICmdArgValString(const bool vbHandleQuotes, const bool vbAcceptNumbers, const bool vbHandleDirPaths) |
| 57 | : m_bHandleQuotedString(vbHandleQuotes) |
| 58 | , m_bAcceptNumbers(vbAcceptNumbers) |
| 59 | , m_bHandleDirPaths(vbHandleDirPaths) |
| 60 | , m_bHandleAnything(false) |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 61 | { |
| 62 | } |
| 63 | |
| 64 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 65 | // Details: CMICmdArgValString constructor. |
| 66 | // Type: Method. |
| 67 | // Args: vrArgName - (R) Argument's name to search by. |
| 68 | // vbMandatory - (R) True = Yes must be present, false = optional argument. |
| 69 | // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. |
| Bruce Mitchener | d0ee89d | 2015-07-03 14:09:56 +0000 | [diff] [blame] | 70 | // vbHandleQuotes - (R) True = Parse a string surrounded by quotes spaces are not delimiters, false = only text up to |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 71 | // next delimiting space character. (Dflt = false) |
| 72 | // vbAcceptNumbers - (R) True = Parse a string and accept as a number if number, false = numbers not recognised as |
| 73 | // string types. (Dflt = false) |
| 74 | // Return: None. |
| 75 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 76 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 77 | CMICmdArgValString::CMICmdArgValString(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd, |
| 78 | const bool vbHandleQuotes /* = false */, const bool vbAcceptNumbers /* = false */) |
| 79 | : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd) |
| 80 | , m_bHandleQuotedString(vbHandleQuotes) |
| 81 | , m_bAcceptNumbers(vbAcceptNumbers) |
| 82 | , m_bHandleDirPaths(false) |
| 83 | , m_bHandleAnything(false) |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 84 | { |
| 85 | } |
| 86 | |
| 87 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 88 | // Details: CMICmdArgValString destructor. |
| 89 | // Type: Overridden. |
| 90 | // Args: None. |
| 91 | // Return: None. |
| 92 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 93 | //-- |
| Bruce Mitchener | e2453af | 2015-08-04 10:24:20 +0000 | [diff] [blame] | 94 | CMICmdArgValString::~CMICmdArgValString() |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | |
| 98 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 99 | // Details: Parse the command's argument options string and try to extract the value *this |
| 100 | // argument is looking for. |
| 101 | // Type: Overridden. |
| 102 | // Args: vrwArgContext - (RW) The command's argument options string. |
| 103 | // Return: MIstatus::success - Functional succeeded. |
| 104 | // MIstatus::failure - Functional failed. |
| 105 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 106 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 107 | bool |
| 108 | CMICmdArgValString::Validate(CMICmdArgContext &vrwArgContext) |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 109 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 110 | if (vrwArgContext.IsEmpty()) |
| Bruce Mitchener | 1425b47 | 2015-06-08 11:15:09 +0000 | [diff] [blame] | 111 | return m_bMandatory ? MIstatus::failure : MIstatus::success; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 112 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 113 | if (m_bHandleQuotedString) |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 114 | return ValidateQuotedText(vrwArgContext); |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 115 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 116 | return ValidateSingleText(vrwArgContext); |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 120 | // Details: Parse the command's argument options string and try to extract only the next |
| 121 | // word delimited by the next space. |
| 122 | // Type: Method. |
| 123 | // Args: vrwArgContext - (RW) The command's argument options string. |
| 124 | // Return: MIstatus::success - Functional succeeded. |
| 125 | // MIstatus::failure - Functional failed. |
| 126 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 127 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 128 | bool |
| 129 | CMICmdArgValString::ValidateSingleText(CMICmdArgContext &vrwArgContext) |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 130 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 131 | const CMIUtilString::VecString_t vecOptions(vrwArgContext.GetArgs()); |
| 132 | CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); |
| 133 | while (it != vecOptions.end()) |
| 134 | { |
| 135 | const CMIUtilString &rArg(*it); |
| 136 | if (IsStringArg(rArg)) |
| 137 | { |
| 138 | m_bFound = true; |
| 139 | |
| 140 | if (vrwArgContext.RemoveArg(rArg)) |
| 141 | { |
| 142 | m_bValid = true; |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 143 | m_argValue = rArg.StripSlashes(); |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 144 | return MIstatus::success; |
| 145 | } |
| 146 | else |
| 147 | return MIstatus::failure; |
| 148 | } |
| 149 | |
| 150 | // Next |
| 151 | ++it; |
| 152 | } |
| 153 | |
| 154 | return MIstatus::failure; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 158 | // Details: Parse the command's argument options string and try to extract all the words |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 159 | // between quotes then delimited by the next space. |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 160 | // Type: Method. |
| 161 | // Args: vrwArgContext - (RW) The command's argument options string. |
| 162 | // Return: MIstatus::success - Functional succeeded. |
| 163 | // MIstatus::failure - Functional failed. |
| 164 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 165 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 166 | bool |
| 167 | CMICmdArgValString::ValidateQuotedText(CMICmdArgContext &vrwArgContext) |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 168 | { |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 169 | const CMIUtilString::VecString_t vecOptions(vrwArgContext.GetArgs()); |
| 170 | if (vecOptions.size() == 0) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 171 | return MIstatus::failure; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 172 | |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 173 | const CMIUtilString &rArg(vecOptions[0]); |
| 174 | if (!IsStringArg(rArg)) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 175 | return MIstatus::failure; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 176 | |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 177 | m_bFound = true; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 178 | |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 179 | if (vrwArgContext.RemoveArg(rArg)) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 180 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 181 | m_bValid = true; |
| Bruce Mitchener | 3b25b47 | 2015-07-03 13:45:34 +0000 | [diff] [blame] | 182 | const char cQuote = '"'; |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 183 | m_argValue = rArg.Trim(cQuote).StripSlashes(); |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 184 | return MIstatus::success; |
| 185 | } |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 186 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 187 | return MIstatus::failure; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 191 | // Details: Examine the string and determine if it is a valid string type argument. |
| 192 | // Type: Method. |
| 193 | // Args: vrTxt - (R) Some text. |
| 194 | // Return: bool - True = yes valid arg, false = no. |
| 195 | // Throws: None. |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 196 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 197 | bool |
| 198 | CMICmdArgValString::IsStringArg(const CMIUtilString &vrTxt) const |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 199 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 200 | if (m_bHandleQuotedString) |
| 201 | return (IsStringArgQuotedText(vrTxt) || IsStringArgQuotedTextEmbedded(vrTxt) || IsStringArgQuotedQuotedTextEmbedded(vrTxt) || |
| 202 | IsStringArgSingleText(vrTxt)); // Still test for this as could just be one word still |
| 203 | |
| 204 | return IsStringArgSingleText(vrTxt); |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 208 | // Details: Examine the string and determine if it is a valid string type argument or |
| 209 | // option value. If the string looks like a long option, short option, a thread |
| 210 | // group ID or just a number it is rejected as a string type value. There is an |
| 211 | // option to allow the string to accept a number as a string type. |
| 212 | // Type: Method. |
| 213 | // Args: vrTxt - (R) Some text. |
| 214 | // Return: bool - True = yes valid argument value, false = something else. |
| 215 | // Throws: None. |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 216 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 217 | bool |
| 218 | CMICmdArgValString::IsStringArgSingleText(const CMIUtilString &vrTxt) const |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 219 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 220 | if (!m_bHandleDirPaths) |
| 221 | { |
| 222 | // Look for directory file paths, if found reject |
| Bruce Mitchener | e8433cc | 2015-09-01 23:57:17 +0000 | [diff] [blame^] | 223 | const bool bHavePosSlash = (vrTxt.find('/') != std::string::npos); |
| 224 | const bool bHaveBckSlash = (vrTxt.find('\\') != std::string::npos); |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 225 | if (bHavePosSlash || bHaveBckSlash) |
| 226 | return false; |
| 227 | } |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 228 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 229 | // Look for --someLongOption, if found reject |
| 230 | if (0 == vrTxt.find("--")) |
| 231 | return false; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 232 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 233 | // Look for -f type short options, if found reject |
| Bruce Mitchener | 0b6ba7c | 2015-07-04 05:16:58 +0000 | [diff] [blame] | 234 | if ((0 == vrTxt.find('-')) && (vrTxt.length() == 2)) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 235 | return false; |
| 236 | |
| 237 | // Look for thread group i1 i2 i3...., if found reject |
| Bruce Mitchener | 0b6ba7c | 2015-07-04 05:16:58 +0000 | [diff] [blame] | 238 | if ((vrTxt.find('i') == 0) && ::isdigit(vrTxt[1])) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 239 | return false; |
| 240 | |
| 241 | // Look for numbers, if found reject |
| 242 | if (!m_bAcceptNumbers && vrTxt.IsNumber()) |
| 243 | return false; |
| 244 | |
| 245 | return true; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 249 | // Details: Examine the string and determine if it is a valid string type argument. |
| 250 | // Take into account quotes surrounding the text. Note this function falls |
| 251 | // through to IsStringArgSingleText() should the criteria match fail. |
| 252 | // Type: Method. |
| 253 | // Args: vrTxt - (R) Some text. |
| 254 | // Return: bool - True = yes valid arg, false = no. |
| 255 | // Throws: None. |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 256 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 257 | bool |
| 258 | CMICmdArgValString::IsStringArgQuotedText(const CMIUtilString &vrTxt) const |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 259 | { |
| Ilia K | 69b95f4 | 2015-02-26 18:21:22 +0000 | [diff] [blame] | 260 | // Accept anything as string word |
| 261 | if (m_bHandleAnything) |
| 262 | return true; |
| 263 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 264 | // CODETAG_QUOTEDTEXT_SIMILAR_CODE |
| Bruce Mitchener | 3b25b47 | 2015-07-03 13:45:34 +0000 | [diff] [blame] | 265 | const char cQuote = '"'; |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 266 | const size_t nPos = vrTxt.find(cQuote); |
| 267 | if (nPos == std::string::npos) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 268 | return false; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 269 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 270 | // Is one and only quote at end of the string |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 271 | if (nPos == (vrTxt.length() - 1)) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 272 | return false; |
| Deepak Panickal | 877569c | 2014-06-24 16:35:50 +0000 | [diff] [blame] | 273 | |
| Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 274 | // Quote must be the first character in the string or be preceded by a space |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 275 | // Also check for embedded string formating quote |
| Bruce Mitchener | 3b25b47 | 2015-07-03 13:45:34 +0000 | [diff] [blame] | 276 | const char cBckSlash = '\\'; |
| 277 | const char cSpace = ' '; |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 278 | if ((nPos > 1) && (vrTxt[nPos - 1] == cBckSlash) && (vrTxt[nPos - 2] != cSpace)) |
| 279 | { |
| 280 | return false; |
| 281 | } |
| 282 | if ((nPos > 0) && (vrTxt[nPos - 1] != cSpace)) |
| 283 | return false; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 284 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 285 | // Need to find the other quote |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 286 | const size_t nPos2 = vrTxt.rfind(cQuote); |
| 287 | if (nPos2 == std::string::npos) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 288 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 289 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 290 | // Make sure not same quote, need two quotes |
| 291 | if (nPos == nPos2) |
| 292 | return MIstatus::failure; |
| 293 | |
| 294 | return true; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 298 | // Details: Examine the string and determine if it is a valid string type argument. |
| 299 | // Take into account quotes surrounding the text. Take into account string format |
| 300 | // embedded quotes surrounding the text i.e. "\\\"%5d\\\"". Note this function falls |
| 301 | // through to IsStringArgQuotedText() should the criteria match fail. |
| 302 | // Type: Method. |
| 303 | // Args: vrTxt - (R) Some text. |
| 304 | // Return: bool - True = yes valid arg, false = no. |
| 305 | // Throws: None. |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 306 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 307 | bool |
| 308 | CMICmdArgValString::IsStringArgQuotedTextEmbedded(const CMIUtilString &vrTxt) const |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 309 | { |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 310 | // CODETAG_QUOTEDTEXT_SIMILAR_CODE |
| Bruce Mitchener | 3b25b47 | 2015-07-03 13:45:34 +0000 | [diff] [blame] | 311 | const char cBckSlash = '\\'; |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 312 | const size_t nPos = vrTxt.find(cBckSlash); |
| 313 | if (nPos == std::string::npos) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 314 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 315 | |
| Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 316 | // Slash must be the first character in the string or be preceded by a space |
| Bruce Mitchener | 3b25b47 | 2015-07-03 13:45:34 +0000 | [diff] [blame] | 317 | const char cSpace = ' '; |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 318 | if ((nPos > 0) && (vrTxt[nPos - 1] != cSpace)) |
| 319 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 320 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 321 | // Need to find the other matching slash |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 322 | const size_t nPos2 = vrTxt.rfind(cBckSlash); |
| 323 | if (nPos2 == std::string::npos) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 324 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 325 | |
| Bruce Mitchener | d0ee89d | 2015-07-03 14:09:56 +0000 | [diff] [blame] | 326 | // Make sure not same back slash, need two slashes |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 327 | if (nPos == nPos2) |
| 328 | return MIstatus::failure; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 329 | |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 330 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | //++ ------------------------------------------------------------------------------------ |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 334 | // Details: Examine the string and determine if it is a valid string type argument. |
| 335 | // Take into account quotes surrounding the text. Take into account string format |
| 336 | // embedded quotes surrounding the text i.e. "\\\"%5d\\\"". Note this function falls |
| 337 | // through to IsStringArgQuotedTextEmbedded() should the criteria match fail. |
| 338 | // Type: Method. |
| 339 | // Args: vrTxt - (R) Some text. |
| 340 | // Return: bool - True = yes valid arg, false = no. |
| 341 | // Throws: None. |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 342 | //-- |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 343 | bool |
| 344 | CMICmdArgValString::IsStringArgQuotedQuotedTextEmbedded(const CMIUtilString &vrTxt) const |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 345 | { |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 346 | const size_t nPos = vrTxt.find("\"\\\""); |
| 347 | if (nPos == std::string::npos) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 348 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 349 | |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 350 | const size_t nPos2 = vrTxt.rfind("\\\"\""); |
| 351 | if (nPos2 == std::string::npos) |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 352 | return false; |
| Deepak Panickal | d249928 | 2014-08-08 16:47:42 +0000 | [diff] [blame] | 353 | |
| Bruce Mitchener | e86c6fa | 2015-07-03 15:40:44 +0000 | [diff] [blame] | 354 | const size_t nLen = vrTxt.length(); |
| Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 355 | if ((nLen > 5) && ((nPos + 2) == (nPos2 - 2))) |
| 356 | return false; |
| 357 | |
| 358 | return true; |
| Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 359 | } |