⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 istring.h

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 H
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program 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.
*/
//---------------------------------------------------------------------------
#ifndef istringH
#define istringH

#include <stdlib.h> // atoi(), itoa()
#include <string>
#include <list>
//---------------------------------------------------------------------------

namespace KCeasyEngine {

using std::string;
using std::list;

// make strings compare case insensitive
inline bool operator ==(const string& lhs, const string& rhs)
{
    return (stricmp(lhs.c_str(),rhs.c_str()) == 0) ? true : false;
}

inline bool operator ==(const char* lhs, const string& rhs)
{
    return (stricmp(lhs,rhs.c_str()) == 0) ? true : false;
}

inline bool operator ==(const string& lhs, const char* rhs)
{
    return (stricmp(lhs.c_str(),rhs) == 0) ? true : false;
}

// int <=> string conversion
inline int string_to_int(string& Str)
{
    return atoi(Str.c_str());
}

inline unsigned int string_to_uint(string& Str)
{
    return (unsigned int)_atoi64(Str.c_str());
}

inline double string_to_float(string& Str)
{
    return atof(Str.c_str());
}

string int_to_string(int Val);
string uint_to_string(unsigned int Val);
string float_to_string(double Val);

string string_tolower(const string& str);
string string_toupper(const string& str);
string string_trim(const string& str);
string string_replace(const string& str, const char* match, const char* replacement);

list<string> string_split(const string& str, const char* separator);
string string_join(const list<string>& strlist, const char* separator);

string FormatNumber(unsigned long Value, const char* BaseUnit = "", int NoOfDecimals = -1);
string FormatTime(unsigned long Seconds);

// base64 encoder/decoder
// caller delete[]s returned data
char* Base64Encode (const unsigned char *data, int src_len);
unsigned char* Base64Decode (const char *data, int *dst_len);

// hex encoder/decoder
// caller delete[]s returned data
char* Base16Encode (const unsigned char *data, int src_len);
unsigned char* Base16Decode (const char *data, int *dst_len);

// url parsing
string UrlDecode(const string& Str);
string UrlEncode(const string& Str);
string FileFromUrl(const string& Url);
string PathFromUrl(const string& Url);
string HostFromUrl(const string& Url);
unsigned int PortFromUrl(const string& Url);
string ProtocolFromUrl(const string& Url);

// path mangling
string SanitizePath(const string& Path);
string DirFromPath(const string& Path);
string FileFromPath(const string& Path);
string UnixToWindowsPath(const string& Path);
string WindowsToUnixPath(const string& Path);

// creates a pronounceable name from binary
string HumanName(const unsigned char* data, int len);

} // namespace KCeasyEngine

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -