advgetopt 2.0.47
Parse complex command line arguments and configuration files in C++.
utils.h
Go to the documentation of this file.
1// Copyright (c) 2006-2024 Made to Order Software Corp. All Rights Reserved
2//
3// https://snapwebsites.org/project/advgetopt
4// contact@m2osw.com
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this program; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#pragma once
20
28// C++
29//
30#include <set>
31#include <string>
32#include <vector>
33
34
35
36namespace advgetopt
37{
38
39
40
41typedef std::vector<std::string> string_list_t;
42typedef std::set<std::string> string_set_t;
43
44constexpr int const DEFAULT_PRIORITY = 50;
45
46
47std::string unquote(std::string const & s, std::string const & pairs = "\"\"''");
48std::string quote(std::string const & s, char open = '"', char close = '\0');
49std::string option_with_dashes(std::string const & s);
50std::string option_with_underscores(std::string const & s);
51void split_string(std::string const & str
53 , string_list_t const & separators);
55 , char const * group_name
56 , char const * project_name
57 , bool add_default_on_empty = true);
58std::string default_group_name(std::string const & filename
59 , char const * group_name
60 , char const * project_name
62std::string handle_user_directory(std::string const & filename);
63bool is_true(std::string s);
64bool is_false(std::string s);
65std::string breakup_line(std::string line
66 , std::size_t const option_width
67 , std::size_t const line_width);
68std::string format_usage_string(std::string const & argument
69 , std::string const & help
70 , std::size_t const option_width
71 , std::size_t const line_width);
72std::size_t get_screen_width();
73std::size_t get_screen_height();
74std::string sanitizer_details();
75std::string escape_shell_argument(std::string const & arg);
76void less(std::basic_ostream<char> & out
77 , std::string const & data);
78
79
80
81} // namespace advgetopt
82// vim: ts=4 sw=4 et
The advgetopt environment to parse command line options.
size_t get_screen_width()
Retrieve the width of one line in your console.
Definition utils.cpp:746
string_list_t insert_group_name(std::string const &filename, char const *group_name, char const *project_name, bool add_default_on_empty)
Insert the group (or project) name in the filename.
Definition utils.cpp:466
void split_string(std::string const &str, string_list_t &result, string_list_t const &separators)
Split a string in sub-strings separated by separators.
Definition utils.cpp:347
bool is_false(std::string s)
Check whether a value represents "false".
Definition utils.cpp:730
std::string breakup_line(std::string line, size_t const option_width, size_t const line_width)
Breakup a string on multiple lines.
Definition utils.cpp:791
constexpr flag_t option_flags_merge()
Definition flags.h:87
void less(std::basic_ostream< char > &out, std::string const &data)
Print out a string to the console or use less.
Definition utils.cpp:1069
std::string format_usage_string(std::string const &argument, std::string const &help, size_t const option_width, size_t const line_width)
Format a help string to make it fit on a given width.
Definition utils.cpp:899
constexpr int const DEFAULT_PRIORITY
Definition utils.h:44
bool is_true(std::string s)
Check whether a value represents "true".
Definition utils.cpp:709
std::string option_with_underscores(std::string const &s)
Converts an option back to using underscores.
Definition utils.cpp:288
std::string escape_shell_argument(std::string const &arg)
Escape special characters from a shell argument.
Definition utils.cpp:959
std::string quote(std::string const &s, char open, char close)
The converse of unquote.
Definition utils.cpp:201
std::set< std::string > string_set_t
Definition utils.h:42
std::string sanitizer_details()
Generate a string describing whether we're using the sanitizer.
Definition utils.cpp:1005
size_t get_screen_height()
Retrieve the height of your console.
Definition utils.cpp:1037
std::string unquote(std::string const &s, std::string const &pairs)
Remove single (') or double (") quotes from a string.
Definition utils.cpp:168
std::string option_with_dashes(std::string const &s)
Convert the _ found in a string to - instead.
Definition utils.cpp:259
std::vector< std::string > string_list_t
Definition utils.h:41
std::string handle_user_directory(std::string const &filename)
Replace a starting ~/... with the contents of the $HOME variable.
Definition utils.cpp:676
std::string default_group_name(std::string const &filename, char const *group_name, char const *project_name, int priority)
Generate the default filename (the ".../50-...")
Definition utils.cpp:585

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.