2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-25 13:56:53 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-03-19 22:11:47 +00:00
|
|
|
#include "common/Common.h"
|
2025-01-06 03:47:11 +00:00
|
|
|
#include <string>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-03-21 08:32:36 +00:00
|
|
|
#include <stdarg.h>
|
2015-10-29 19:52:55 +00:00
|
|
|
#include <vector>
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow {
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
//! std::string utilities
|
2014-03-21 08:32:36 +00:00
|
|
|
/*!
|
|
|
|
|
Provides functions for string manipulation.
|
|
|
|
|
*/
|
|
|
|
|
namespace string {
|
|
|
|
|
|
|
|
|
|
//! Format positional arguments
|
|
|
|
|
/*!
|
|
|
|
|
Format a string using positional arguments. fmt has literal
|
|
|
|
|
characters and conversion specifications introduced by `\%':
|
|
|
|
|
- \%\% -- literal `\%'
|
|
|
|
|
- \%{n} -- positional element n, n a positive integer, {} are literal
|
|
|
|
|
|
|
|
|
|
All arguments in the variable list are const char*. Positional
|
|
|
|
|
elements are indexed from 1.
|
|
|
|
|
*/
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string format(const char *fmt, ...);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
|
//! Format positional arguments
|
|
|
|
|
/*!
|
|
|
|
|
Same as format() except takes va_list.
|
|
|
|
|
*/
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string vformat(const char *fmt, va_list);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
|
//! Print a string using sprintf-style formatting
|
|
|
|
|
/*!
|
2014-11-11 13:51:47 +00:00
|
|
|
Equivalent to sprintf() except the result is returned as a String.
|
2014-03-21 08:32:36 +00:00
|
|
|
*/
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string sprintf(const char *fmt, ...);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2015-04-02 13:01:50 +00:00
|
|
|
//! Convert into hexdecimal
|
|
|
|
|
/*!
|
|
|
|
|
Convert each character in \c subject into hexdecimal form with \c width
|
2025-01-25 12:54:33 +00:00
|
|
|
Return a new hexString
|
2015-04-02 13:01:50 +00:00
|
|
|
*/
|
2025-01-25 12:54:33 +00:00
|
|
|
std::string toHex(const std::string &subject, int width, const char fill = '0');
|
2015-04-02 13:01:50 +00:00
|
|
|
|
2025-01-29 02:15:50 +00:00
|
|
|
/**
|
|
|
|
|
* @brief toHex Convert each value in input into a hex string
|
|
|
|
|
* @param input vector of uint8_t
|
|
|
|
|
* @param width
|
|
|
|
|
* @param fill fill character 0 is default
|
|
|
|
|
* @return a hex string
|
|
|
|
|
*/
|
|
|
|
|
std::string toHex(const std::vector<uint8_t> &input, int width, const char fill = '0');
|
|
|
|
|
|
2025-01-25 13:08:03 +00:00
|
|
|
/**
|
|
|
|
|
* @brief fromHexChar Convert a single char to its hexidecmal value
|
|
|
|
|
* @param c input char 0-F
|
|
|
|
|
* @return The value of c in Hex or -1 for invalid hex chars
|
|
|
|
|
*/
|
|
|
|
|
int fromHexChar(char c);
|
|
|
|
|
|
2025-01-25 13:39:13 +00:00
|
|
|
/**
|
|
|
|
|
* @brief fromHex Turn the string into a std::vector<uint8_t>
|
|
|
|
|
* @param hexString a Hexidecimal string
|
|
|
|
|
* @return std::vector<uint8_t> version of the hex chars
|
|
|
|
|
*/
|
|
|
|
|
std::vector<uint8_t> fromHex(const std::string &hexString);
|
|
|
|
|
|
2015-04-02 13:01:50 +00:00
|
|
|
//! Convert to all uppercase
|
|
|
|
|
/*!
|
|
|
|
|
Convert each character in \c subject to uppercase
|
|
|
|
|
*/
|
2025-01-06 00:55:07 +00:00
|
|
|
void uppercase(std::string &subject);
|
2015-04-02 13:01:50 +00:00
|
|
|
|
2015-05-19 21:23:43 +00:00
|
|
|
//! Convert a size type to a string
|
2015-05-18 18:27:54 +00:00
|
|
|
/*!
|
2015-05-19 21:23:43 +00:00
|
|
|
Convert an size type to a string
|
2015-05-18 18:27:54 +00:00
|
|
|
*/
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string sizeTypeToString(size_t n);
|
2015-05-19 21:23:43 +00:00
|
|
|
|
|
|
|
|
//! Convert a string to a size type
|
|
|
|
|
/*!
|
|
|
|
|
Convert an a \c string to an size type
|
|
|
|
|
*/
|
2025-01-06 00:55:07 +00:00
|
|
|
size_t stringToSizeType(std::string string);
|
2015-04-02 13:01:50 +00:00
|
|
|
|
2014-03-21 08:32:36 +00:00
|
|
|
//! Case-insensitive comparisons
|
|
|
|
|
/*!
|
|
|
|
|
This class provides case-insensitve comparison functions.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class CaselessCmp
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
public:
|
|
|
|
|
//! Same as less()
|
2025-01-06 00:55:07 +00:00
|
|
|
bool operator()(const std::string &a, const std::string &b) const;
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Returns true iff \c a is lexicographically less than \c b
|
2025-01-06 00:55:07 +00:00
|
|
|
static bool less(const std::string &a, const std::string &b);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Returns true iff \c a is lexicographically equal to \c b
|
2025-01-06 00:55:07 +00:00
|
|
|
static bool equal(const std::string &a, const std::string &b);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Returns true iff \c a is lexicographically less than \c b
|
2025-01-06 00:55:07 +00:00
|
|
|
static bool cmpLess(const std::string::value_type &a, const std::string::value_type &b);
|
2014-03-21 08:32:36 +00:00
|
|
|
};
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
} // namespace string
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow
|