Get a vector of short names, one of long names, and a single name
| 1922 | |
| 1923 | /// Get a vector of short names, one of long names, and a single name |
| 1924 | inline std::tuple<std::vector<std::string>, std::vector<std::string>, std::string> get_names( |
| 1925 | const std::vector<std::string> &input) { |
| 1926 | std::vector<std::string> short_names; |
| 1927 | std::vector<std::string> long_names; |
| 1928 | std::string pos_name; |
| 1929 | |
| 1930 | for (std::string name : input) { |
| 1931 | if (name.length() == 0) { |
| 1932 | continue; |
| 1933 | } |
| 1934 | if (name.length() > 1 && name[0] == '-' && name[1] != '-') { |
| 1935 | if (name.length() == 2 && valid_first_char(name[1])) |
| 1936 | short_names.emplace_back(1, name[1]); |
| 1937 | else |
| 1938 | throw BadNameString::OneCharName(name); |
| 1939 | } else if (name.length() > 2 && name.substr(0, 2) == "--") { |
| 1940 | name = name.substr(2); |
| 1941 | if (valid_name_string(name)) |
| 1942 | long_names.push_back(name); |
| 1943 | else |
| 1944 | throw BadNameString::BadLongName(name); |
| 1945 | } else if (name == "-" || name == "--") { |
| 1946 | throw BadNameString::DashesOnly(name); |
| 1947 | } else { |
| 1948 | if (pos_name.length() > 0) throw BadNameString::MultiPositionalNames(name); |
| 1949 | pos_name = name; |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | return std::tuple<std::vector<std::string>, std::vector<std::string>, std::string>(short_names, long_names, pos_name); |
| 1954 | } |
| 1955 | |
| 1956 | } // namespace detail |
| 1957 | } // namespace CLI |
no test coverage detected