|
|
|
|
/******************************************************************************
|
|
|
|
|
* File - StringManip.h
|
|
|
|
|
* Author - Joey Pollack
|
|
|
|
|
* Date - 2018/10/12 (y/m/d)
|
|
|
|
|
* Mod Date - 2018/10/12 (y/m/d)
|
|
|
|
|
* Description - Functions for working with std::string objects
|
|
|
|
|
*
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef STRING_MANIP_H_
|
|
|
|
|
#define STRING_MANIP_H_
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace jpUtils
|
|
|
|
|
{
|
|
|
|
|
class StringManip
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
// Generic string helpers
|
|
|
|
|
// ===========================================================
|
|
|
|
|
static std::string ToUpper(std::string str);
|
|
|
|
|
static std::string ToLower(std::string str);
|
|
|
|
|
|
|
|
|
|
// Splits the string based on the given delimiter,
|
|
|
|
|
// maxSplit = -1 for unlimited number of splits
|
|
|
|
|
static std::vector<std::string> Split(std::string str, char delim = ' ', int maxSplits = -1);
|
|
|
|
|
|
|
|
|
|
// Trim given delimiters from start and end of string
|
|
|
|
|
static std::string Trim(std::string str, std::string delims = " \r\n\t");
|
|
|
|
|
|
|
|
|
|
// Trim given delimiters from start of string
|
|
|
|
|
static std::string TrimStart(std::string str, std::string delims = " \r\n\t");
|
|
|
|
|
|
|
|
|
|
// Trim given delimiters from end of string
|
|
|
|
|
static std::string TrimEnd(std::string str, std::string delims);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// File path helpers
|
|
|
|
|
// ===========================================================
|
|
|
|
|
static std::string GetFileNameFromPath(std::string path, bool includeExt = true);
|
|
|
|
|
static std::string TrimFileNameFromPath(std::string path);
|
|
|
|
|
static std::string GetFileExtension(std::string filename);
|
|
|
|
|
|
|
|
|
|
// Type Conversion
|
|
|
|
|
// ===========================================================
|
|
|
|
|
static int AsInt(std::string value);
|
|
|
|
|
static double AsDouble(std::string value);
|
|
|
|
|
static bool AsBool(std::string value);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // STRING_MANIP_H_
|