1 //===-- MICmdArgValOptionShort.cpp ------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "MICmdArgValOptionShort.h"
11 #include "MICmdArgContext.h"
14 // Details: CMICmdArgValOptionShort constructor.
20 CMICmdArgValOptionShort::CMICmdArgValOptionShort() {}
23 // Details: CMICmdArgValOptionShort constructor.
25 // Args: vrArgName - (R) Argument's name to search by.
26 // vbMandatory - (R) True = Yes must be present, false = optional
28 // vbHandleByCmd - (R) True = Command processes *this option, false =
33 CMICmdArgValOptionShort::CMICmdArgValOptionShort(const CMIUtilString &vrArgName,
34 const bool vbMandatory,
35 const bool vbHandleByCmd)
36 : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd) {}
39 // Details: CMICmdArgValOptionLong constructor.
41 // Args: vrArgName - (R) Argument's name to search by.
42 // vbMandatory - (R) True = Yes must be present, false =
44 // vbHandleByCmd - (R) True = Command processes *this option,
45 // false = not handled.
46 // veType - (R) The type of argument to look for and
47 // create argument object of a certain type.
48 // vnExpectingNOptions - (R) The number of options expected to read
49 // following *this argument.
53 CMICmdArgValOptionShort::CMICmdArgValOptionShort(
54 const CMIUtilString &vrArgName, const bool vbMandatory,
55 const bool vbHandleByCmd, const ArgValType_e veType,
56 const MIuint vnExpectingNOptions)
57 : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd, veType,
58 vnExpectingNOptions) {}
61 // Details: CMICmdArgValOptionShort destructor.
67 CMICmdArgValOptionShort::~CMICmdArgValOptionShort() {}
70 // Details: Examine the string and determine if it is a valid short type option
73 // Args: vrTxt - (R) Some text.
74 // Return: bool - True = yes valid arg, false = no.
77 bool CMICmdArgValOptionShort::IsArgShortOption(
78 const CMIUtilString &vrTxt) const {
79 // Look for --someLongOption
80 MIint nPos = vrTxt.find("--");
84 // Look for -f short option
85 nPos = vrTxt.find('-');
89 if (vrTxt.length() > 2)
96 // Details: Examine the string and determine if it is a valid short type option
98 // Long type argument looks like -f some short option.
100 // Args: vrTxt - (R) Some text.
101 // Return: bool - True = yes valid arg, false = no.
104 bool CMICmdArgValOptionShort::IsArgOptionCorrect(
105 const CMIUtilString &vrTxt) const {
106 return IsArgShortOption(vrTxt);
110 // Details: Does the argument name of the argument being parsed ATM match the
112 // *this argument object.
114 // Args: vrTxt - (R) Some text.
115 // Return: bool - True = yes arg name matched, false = no.
118 bool CMICmdArgValOptionShort::ArgNameMatch(const CMIUtilString &vrTxt) const {
119 const CMIUtilString strArg = vrTxt.substr(1);
120 return (strArg == GetName());