2008-12-10 05:42:49 +01:00
|
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
|
* This file is a part of Winix
|
2008-12-10 05:42:49 +01:00
|
|
|
|
* and is not publicly distributed
|
|
|
|
|
*
|
2010-02-28 22:33:06 +01:00
|
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-21 22:50:55 +02:00
|
|
|
|
#ifndef headerfilecmslucoremisc
|
|
|
|
|
#define headerfilecmslucoremisc
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <sstream>
|
2009-03-23 00:54:15 +01:00
|
|
|
|
#include <ctime>
|
2010-06-03 19:38:18 +02:00
|
|
|
|
#include <cstdio>
|
2010-10-24 01:12:47 +02:00
|
|
|
|
#include "item.h"
|
2010-05-20 20:28:19 +02:00
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
int Atoi(const std::string & str, int base = 10);
|
|
|
|
|
int Atoi(const std::wstring & str, int base = 10);
|
|
|
|
|
int Atoi(const char * str, int base = 10);
|
|
|
|
|
int Atoi(const wchar_t * str, int base = 10);
|
|
|
|
|
|
|
|
|
|
long Atol(const std::string & str, int base = 10);
|
|
|
|
|
long Atol(const std::wstring & str, int base = 10);
|
|
|
|
|
long Atol(const char * str, int base = 10);
|
|
|
|
|
long Atol(const wchar_t * str, int base = 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// warning: it uses its own static buffer
|
|
|
|
|
// one buffer for both these functions
|
|
|
|
|
const wchar_t * Itoa(int value, int base = 10);
|
|
|
|
|
const wchar_t * Ltoa(long value, int base = 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AssignString(const char * src, std::wstring & dst, bool clear = true);
|
|
|
|
|
void AssignString(const std::string & src, std::wstring & dst, bool clear = true);
|
|
|
|
|
void AssignString(const wchar_t * src, std::string & dst, bool clear = true);
|
|
|
|
|
void AssignString(const std::wstring & src, std::string & dst, bool clear = true);
|
|
|
|
|
void AssignString(const std::string & src, std::string & dst, bool clear = true);
|
|
|
|
|
void AssignString(const std::wstring & src, std::wstring & dst, bool clear = true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
void ToString(std::string & s, int value);
|
|
|
|
|
void ToString(std::string & s, long value);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
void ToString(std::wstring & s, int value);
|
|
|
|
|
void ToString(std::wstring & s, long value);
|
|
|
|
|
|
|
|
|
|
//int ChangeLocalChar(unsigned char c);
|
|
|
|
|
|
|
|
|
|
bool CorrectUrlChar(wchar_t c);
|
|
|
|
|
void CorrectUrlDots(std::wstring & url);
|
|
|
|
|
void CorrectUrlChars(std::wstring & url);
|
|
|
|
|
void CorrectUrlOnlyAllowedChar(std::wstring & url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const wchar_t * DateToStr(int year, int month, int day);
|
|
|
|
|
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec);
|
|
|
|
|
const wchar_t * DateToStr(const tm * ptm);
|
|
|
|
|
const wchar_t * DateToStr(const tm & rtm);
|
|
|
|
|
const wchar_t * DateToStr(time_t t);
|
|
|
|
|
const wchar_t * DateToStrWithoutHours(const tm * ptm);
|
|
|
|
|
const wchar_t * DateToStrWithoutHours(const tm & rtm);
|
|
|
|
|
const wchar_t * DateToStrWithoutHours(time_t t);
|
2009-11-21 00:09:52 +01:00
|
|
|
|
|
|
|
|
|
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec);
|
2010-10-24 01:12:47 +02:00
|
|
|
|
const char * DateToStrCookie(const tm * ptm);
|
|
|
|
|
const char * DateToStrCookie(const tm & rtm);
|
2009-11-21 00:09:52 +01:00
|
|
|
|
const char * DateToStrCookie(time_t t);
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
const wchar_t * IpToStr(unsigned int ip_);
|
|
|
|
|
|
|
|
|
|
bool IsWhite(wchar_t s);
|
|
|
|
|
|
|
|
|
|
template<class StringType>
|
|
|
|
|
void TrimWhite(StringType & s)
|
|
|
|
|
{
|
|
|
|
|
typename StringType::size_type i;
|
|
|
|
|
|
|
|
|
|
if( s.empty() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// looking for white characters at the end
|
|
|
|
|
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
|
|
|
|
|
|
|
|
|
if( i==0 && IsWhite(s[i]) )
|
|
|
|
|
{
|
|
|
|
|
// the whole string has white characters
|
|
|
|
|
s.clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deleting white characters at the end
|
|
|
|
|
if( i != s.size() - 1 )
|
|
|
|
|
s.erase(i+1, StringType::npos);
|
|
|
|
|
|
|
|
|
|
// looking for white characters at the beginning
|
|
|
|
|
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
|
|
|
|
|
|
|
|
|
// deleting white characters at the beginning
|
|
|
|
|
if( i != 0 )
|
|
|
|
|
s.erase(0, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType>
|
|
|
|
|
void Trim(StringType & s, wchar_t c)
|
|
|
|
|
{
|
|
|
|
|
typename StringType::size_type i;
|
|
|
|
|
|
|
|
|
|
if( s.empty() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// looking for the 'c' characters at the end
|
|
|
|
|
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
|
|
|
|
|
|
|
|
|
|
if( i==0 && s[i]==c )
|
|
|
|
|
{
|
|
|
|
|
// the whole string has the 'c' characters
|
|
|
|
|
s.clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deleting 'c' characters at the end
|
|
|
|
|
if( i != s.size() - 1 )
|
|
|
|
|
s.erase(i+1, StringType::npos);
|
|
|
|
|
|
|
|
|
|
// looking for the 'c' characters at the beginning
|
|
|
|
|
for(i=0 ; i<s.size() && s[i]==c ; ++i);
|
|
|
|
|
|
|
|
|
|
// deleting the 'c' characters at the beginning
|
|
|
|
|
if( i != 0 )
|
|
|
|
|
s.erase(0, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wchar_t ToSmall(wchar_t c);
|
|
|
|
|
void ToSmall(std::wstring & s);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
2009-11-17 00:36:38 +01:00
|
|
|
|
const char * SkipWhite(const char * s);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
const wchar_t * SkipWhite(const wchar_t * s);
|
2009-11-18 02:58:38 +01:00
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
const wchar_t * ToStr(int value); // !! zamienic na ToString() tak jak pozosta<74>e metody (na poczatku)
|
|
|
|
|
|
|
|
|
|
/*
|
2009-12-30 21:46:12 +01:00
|
|
|
|
bool IsSubString(const char * short_str, const char * long_str);
|
2010-10-19 02:31:20 +02:00
|
|
|
|
bool IsSubString(const std::string & short_str, const std::string & long_str);
|
2009-12-30 21:46:12 +01:00
|
|
|
|
bool IsSubStringNoCase(const char * short_str, const char * long_str);
|
2010-10-19 02:31:20 +02:00
|
|
|
|
bool IsSubStringNoCase(const std::string & short_str, const std::string & long_str);
|
2010-02-13 00:16:13 +01:00
|
|
|
|
bool EqualNoCase(const char * str1, const char * str2);
|
2010-10-02 01:20:03 +02:00
|
|
|
|
bool EqualNoCase(const std::string & str1, const std::string & str2);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool IsSubString(const StringType1 * short_str, const StringType2 * long_str)
|
|
|
|
|
{
|
|
|
|
|
while( *short_str && *long_str && wchar_t(*short_str) == wchar_t(*long_str) )
|
|
|
|
|
{
|
|
|
|
|
++short_str;
|
|
|
|
|
++long_str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( *short_str == 0 )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool IsSubString(const StringType1 & short_str, const StringType2 & long_str)
|
|
|
|
|
{
|
|
|
|
|
return IsSubString(short_str.c_str(), long_str.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool IsSubStringNoCase(const StringType1 * short_str, const StringType2 * long_str)
|
|
|
|
|
{
|
|
|
|
|
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
|
|
|
|
|
{
|
|
|
|
|
++short_str;
|
|
|
|
|
++long_str;
|
|
|
|
|
}
|
2009-06-05 22:29:06 +02:00
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
if( *short_str == 0 )
|
|
|
|
|
return true;
|
2009-10-01 00:31:20 +02:00
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool IsSubStringNoCase(const StringType1 & short_str, const StringType2 & long_str)
|
|
|
|
|
{
|
|
|
|
|
return IsSubStringNoCase(short_str.c_str(), long_str.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool Equal(const StringType1 * str1, const StringType2 * str2)
|
|
|
|
|
{
|
|
|
|
|
while( *str1 && *str2 && wchar_t(*str1) == wchar_t(*str2) )
|
|
|
|
|
{
|
|
|
|
|
++str1;
|
|
|
|
|
++str2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( *str1 == 0 && *str2 == 0 )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool Equal(const StringType1 & str1, const StringType2 & str2)
|
|
|
|
|
{
|
|
|
|
|
return Equal(str1.c_str(), str2.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool EqualNoCase(const StringType1 * str1, const StringType2 * str2)
|
|
|
|
|
{
|
|
|
|
|
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
|
|
|
|
{
|
|
|
|
|
++str1;
|
|
|
|
|
++str2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( *str1 == 0 && *str2 == 0 )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType1, class StringType2>
|
|
|
|
|
bool EqualNoCase(const StringType1 & str1, const StringType2 & str2)
|
|
|
|
|
{
|
|
|
|
|
return EqualNoCase(str1.c_str(), str2.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType>
|
|
|
|
|
void NoLastSlash(StringType & s)
|
|
|
|
|
{
|
|
|
|
|
if( s.empty() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
size_t i = s.size();
|
|
|
|
|
|
|
|
|
|
for( ; i>0 && s[i-1]=='/' ; --i);
|
|
|
|
|
|
|
|
|
|
if( i < s.size() )
|
|
|
|
|
s.erase(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringType>
|
|
|
|
|
void NoFirstHttp(StringType & s)
|
|
|
|
|
{
|
|
|
|
|
if( s.empty() )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const char http[] = "http://";
|
|
|
|
|
const char https[] = "https://";
|
|
|
|
|
|
|
|
|
|
if( IsSubStringNoCase(http, s.c_str()) )
|
|
|
|
|
{
|
|
|
|
|
s.erase(0, sizeof(http)/sizeof(char));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if( IsSubStringNoCase(https, s.c_str()) )
|
|
|
|
|
{
|
|
|
|
|
s.erase(0, sizeof(https)/sizeof(char));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ValidateEmail(const std::wstring & email);
|
|
|
|
|
|
|
|
|
|
bool IsFile(const wchar_t * file);
|
|
|
|
|
bool IsFile(const std::wstring & file);
|
|
|
|
|
bool CreateDir(const wchar_t * dir, int priv);
|
|
|
|
|
bool CreateDir(const std::wstring & dir, int priv);
|
|
|
|
|
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv);
|
|
|
|
|
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
2010-06-03 19:38:18 +02:00
|
|
|
|
bool CopyFile(FILE * in, FILE * out);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
|
|
|
|
bool CopyFile(const std::wstring & src, const std::wstring & dst);
|
|
|
|
|
|
|
|
|
|
bool RemoveFile(const wchar_t * file);
|
|
|
|
|
bool RemoveFile(const std::wstring & file);
|
|
|
|
|
|
|
|
|
|
bool RenameFile(const wchar_t * from, const wchar_t * to);
|
|
|
|
|
bool RenameFile(const std::wstring & from, const std::wstring & to);
|
2010-06-03 19:38:18 +02:00
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
const wchar_t * GetFileExt(const wchar_t * name);
|
|
|
|
|
Item::Auth SelectFileType(const wchar_t * file_name);
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
|
time_t Time(const tm & par);
|
|
|
|
|
time_t Time(const tm * par);
|
|
|
|
|
tm Time(time_t par);
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
#endif
|