deskflow/src/lib/base/String.h

81 lines
2 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +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
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "common/Common.h"
2012-06-10 16:50:54 +00:00
#include <string>
namespace deskflow {
//! std::string utilities
/*!
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.
*/
std::string format(const char *fmt, ...);
//! Format positional arguments
/*!
Same as format() except takes va_list.
*/
std::string vformat(const char *fmt, va_list);
//! 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.
*/
std::string sprintf(const char *fmt, ...);
//! Convert a size type to a string
2015-05-18 18:27:54 +00:00
/*!
Convert an size type to a string
2015-05-18 18:27:54 +00:00
*/
std::string sizeTypeToString(size_t n);
//! Convert a string to a size type
/*!
Convert an a \c string to an size type
*/
size_t stringToSizeType(std::string string);
//! Case-insensitive comparisons
/*!
This class provides case-insensitve comparison functions.
*/
class CaselessCmp
{
public:
//! Same as less()
bool operator()(const std::string &a, const std::string &b) const;
//! Returns true iff \c a is lexicographically less than \c b
static bool less(const std::string_view &a, const std::string_view &b);
//! Returns true iff \c a is lexicographically equal to \c b
static bool equal(const std::string &a, const std::string &b);
//! Returns true iff \c a is lexicographically less than \c b
static bool cmpLess(const std::string::value_type &a, const std::string::value_type &b);
};
} // namespace string
} // namespace deskflow