2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2014-11-02 12:12:05 +00:00
|
|
|
* Copyright (C) 2012 Synergy Si Ltd.
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/stdstring.h"
|
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
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
// use standard C++ string class for our string class
|
2014-11-11 13:51:47 +00:00
|
|
|
typedef std::string String;
|
2014-03-14 20:34:19 +00:00
|
|
|
|
2014-03-21 08:32:36 +00:00
|
|
|
namespace synergy {
|
|
|
|
|
|
|
|
//! 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.
|
|
|
|
*/
|
2014-11-11 13:51:47 +00:00
|
|
|
String format(const char* fmt, ...);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
//! Format positional arguments
|
|
|
|
/*!
|
|
|
|
Same as format() except takes va_list.
|
|
|
|
*/
|
2014-11-11 13:51:47 +00:00
|
|
|
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
|
|
|
*/
|
2014-11-11 13:51:47 +00:00
|
|
|
String sprintf(const char* fmt, ...);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
//! Find and replace all
|
|
|
|
/*!
|
|
|
|
Finds \c find inside \c subject and replaces it with \c replace
|
|
|
|
*/
|
2014-11-11 13:51:47 +00:00
|
|
|
void findReplaceAll(String& subject, const String& find, const String& replace);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
2015-01-09 13:46:35 +00:00
|
|
|
//! Remove file extension
|
|
|
|
/*!
|
|
|
|
Finds the last dot and remove all characters from the dot to the end
|
|
|
|
*/
|
|
|
|
String removeFileExt(String filename);
|
|
|
|
|
2015-04-02 13:01:50 +00:00
|
|
|
//! Convert into hexdecimal
|
|
|
|
/*!
|
|
|
|
Convert each character in \c subject into hexdecimal form with \c width
|
|
|
|
*/
|
2015-04-14 12:44:10 +00:00
|
|
|
void toHex(String& subject, int width, const char fill = '0');
|
2015-04-02 13:01:50 +00:00
|
|
|
|
|
|
|
//! Convert to all uppercase
|
|
|
|
/*!
|
|
|
|
Convert each character in \c subject to uppercase
|
|
|
|
*/
|
2015-04-14 12:44:10 +00:00
|
|
|
void uppercase(String& subject);
|
2015-04-02 13:01:50 +00:00
|
|
|
|
|
|
|
//! Remove all specific char in suject
|
|
|
|
/*!
|
2015-05-18 18:27:54 +00:00
|
|
|
Remove all specific \c c in \c suject
|
2015-04-02 13:01:50 +00:00
|
|
|
*/
|
2015-04-14 12:44:10 +00:00
|
|
|
void removeChar(String& subject, const char c);
|
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
|
|
|
*/
|
2015-05-19 21:23:43 +00:00
|
|
|
String sizeTypeToString(size_t n);
|
|
|
|
|
|
|
|
//! Convert a string to a size type
|
|
|
|
/*!
|
|
|
|
Convert an a \c string to an size type
|
|
|
|
*/
|
|
|
|
size_t stringToSizeType(String string);
|
2015-04-02 13:01:50 +00:00
|
|
|
|
2015-10-29 19:52:55 +00:00
|
|
|
//! Split a string into substrings
|
|
|
|
/*!
|
|
|
|
Split a \c string that separated by a \c c into substrings
|
|
|
|
*/
|
|
|
|
std::vector<String> splitString(String string, const char c);
|
|
|
|
|
2014-03-21 08:32:36 +00:00
|
|
|
//! Case-insensitive comparisons
|
|
|
|
/*!
|
|
|
|
This class provides case-insensitve comparison functions.
|
|
|
|
*/
|
|
|
|
class CaselessCmp {
|
|
|
|
public:
|
|
|
|
//! Same as less()
|
2014-11-11 13:51:47 +00:00
|
|
|
bool operator()(const String& a, const String& b) const;
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
//! Returns true iff \c a is lexicographically less than \c b
|
2014-11-11 13:51:47 +00:00
|
|
|
static bool less(const String& a, const String& b);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
//! Returns true iff \c a is lexicographically equal to \c b
|
2014-11-11 13:51:47 +00:00
|
|
|
static bool equal(const String& a, const String& b);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
//! Returns true iff \c a is lexicographically less than \c b
|
2014-11-11 13:51:47 +00:00
|
|
|
static bool cmpLess(const String::value_type& a,
|
|
|
|
const String::value_type& b);
|
2014-03-21 08:32:36 +00:00
|
|
|
|
|
|
|
//! Returns true iff \c a is lexicographically equal to \c b
|
2014-11-11 13:51:47 +00:00
|
|
|
static bool cmpEqual(const String::value_type& a,
|
|
|
|
const String::value_type& b);
|
2014-03-21 08:32:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|