2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-02-25 00:12:45 +01:00
|
|
|
* Copyright (c) 2008-2021, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-12-10 05:42:49 +01:00
|
|
|
*/
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2014-09-28 19:30:05 +02:00
|
|
|
#include <grp.h>
|
2011-06-24 22:53:21 +02:00
|
|
|
#include <fstream>
|
2013-03-29 23:03:28 +01:00
|
|
|
#include <cstdlib>
|
2008-12-10 05:42:49 +01:00
|
|
|
#include "misc.h"
|
2010-11-21 01:19:17 +01:00
|
|
|
#include "templates/templates.h"
|
2018-05-25 19:22:12 +02:00
|
|
|
#include "convert/convert.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
namespace misc_private
|
|
|
|
{
|
2012-02-28 22:09:44 +01:00
|
|
|
// white_chars table should be sorted
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
// we do not treat a new line character (10) as a white character here
|
2012-02-28 22:09:44 +01:00
|
|
|
static const wchar_t white_chars[] = { 0x0009, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0,
|
|
|
|
0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004,
|
|
|
|
0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028,
|
|
|
|
0x2029, 0x202F, 0x205F, 0x3000 };
|
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::WTextStream tmp_qencode;
|
2011-06-24 22:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
/*
|
|
|
|
* IMPROVE ME
|
|
|
|
* we ca add our own functions with treat_new_line_as_white flag
|
|
|
|
* and with a pointer pointing after the number
|
|
|
|
*
|
|
|
|
* Toi(const wchar_t * str, const wchar_t ** str_after, bool treat_new_line_as_white);
|
|
|
|
* Toi(const wchar_t * str, bool treat_new_line_as_white);
|
|
|
|
* Toi(const std::wstring & str, bool treat_new_line_as_white);
|
|
|
|
*
|
|
|
|
*/
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
int Toi(const std::string & str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
return Toi(str.c_str(), base);
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
int Toi(const std::wstring & str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
return Toi(str.c_str(), base);
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
int Toi(const char * str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
|
|
|
return static_cast<int>(strtol(str, 0, base));
|
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
int Toi(const wchar_t * str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
|
|
|
return static_cast<int>(wcstol(str, 0, base));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
long Tol(const std::string & str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
return Tol(str.c_str(), base);
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
long Tol(const std::wstring & str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
return Tol(str.c_str(), base);
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
long Tol(const char * str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
|
|
|
return strtol(str, 0, base);
|
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
long Tol(const wchar_t * str, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
|
|
|
return wcstol(str, 0, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
|
2013-03-29 23:03:28 +01:00
|
|
|
double Tod(const std::string & str)
|
|
|
|
{
|
|
|
|
return strtod(str.c_str(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Tod(const std::wstring & str)
|
|
|
|
{
|
|
|
|
return wcstold(str.c_str(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Tod(const char * str)
|
|
|
|
{
|
|
|
|
return strtod(str, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Tod(const wchar_t * str)
|
|
|
|
{
|
|
|
|
return wcstold(str, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
|
|
|
|
const wchar_t * Toa(unsigned int value, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
return Toa(static_cast<unsigned long>(value), base);
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
const wchar_t * Toa(unsigned long value, int base)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
static wchar_t buffer[50];
|
|
|
|
size_t len = sizeof(buffer) / sizeof(wchar_t);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
Toa(value, buffer, len, base);
|
2008-12-10 05:42:49 +01:00
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
2008-12-10 05:42:49 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
const wchar_t * Toa(int value, int base)
|
|
|
|
{
|
|
|
|
return Toa(static_cast<long>(value), base);
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
const wchar_t * Toa(long value, int base)
|
|
|
|
{
|
|
|
|
static wchar_t buffer[50];
|
|
|
|
size_t len = sizeof(buffer) / sizeof(wchar_t);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
Toa(value, buffer, len, base);
|
|
|
|
|
|
|
|
return buffer;
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
void Toa(int value, std::string & res, int base, bool clear)
|
2010-11-21 01:19:17 +01:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
static char buffer[50]; // !! IMPROVE ME this 'static' is not needed here?
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
size_t len = sizeof(buffer) / sizeof(char);
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
if( clear )
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
res.clear();
|
2010-11-21 01:19:17 +01:00
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
Toa(value, buffer, len, base);
|
|
|
|
res += buffer;
|
|
|
|
}
|
2010-11-23 22:52:25 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
void Toa(long value, std::string & res, int base, bool clear)
|
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
static char buffer[50]; // !! IMPROVE ME the same as above
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
size_t len = sizeof(buffer) / sizeof(char);
|
|
|
|
|
|
|
|
if( clear )
|
|
|
|
res.clear();
|
|
|
|
|
|
|
|
Toa(value, buffer, len, base);
|
|
|
|
res += buffer;
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
void Toa(int value, std::wstring & res, int base, bool clear)
|
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
static wchar_t buffer[50]; // !!
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
size_t len = sizeof(buffer) / sizeof(wchar_t);
|
|
|
|
|
|
|
|
if( clear )
|
|
|
|
res.clear();
|
|
|
|
|
|
|
|
Toa(value, buffer, len, base);
|
|
|
|
res += buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toa(long value, std::wstring & res, int base, bool clear)
|
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
static wchar_t buffer[50]; // !!
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
size_t len = sizeof(buffer) / sizeof(wchar_t);
|
|
|
|
|
|
|
|
if( clear )
|
|
|
|
res.clear();
|
|
|
|
|
|
|
|
Toa(value, buffer, len, base);
|
|
|
|
res += buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-22 16:30:56 +01:00
|
|
|
void SetNonZeroDigitsAfterComma(char * str, size_t digits)
|
|
|
|
{
|
|
|
|
bool was_comma = false;
|
|
|
|
bool was_not_zero = false;
|
|
|
|
size_t zeroes = 0;
|
|
|
|
size_t not_zeroes = 0;
|
|
|
|
|
|
|
|
for(size_t i=0 ; str[i] != 0 ; ++i)
|
|
|
|
{
|
|
|
|
if( str[i] == '.' || str[i] == ',' )
|
|
|
|
{
|
|
|
|
was_comma = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( was_comma )
|
|
|
|
{
|
|
|
|
if( str[i] == '0' && !was_not_zero )
|
|
|
|
{
|
|
|
|
zeroes += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
was_not_zero = true;
|
|
|
|
not_zeroes += 1;
|
|
|
|
|
|
|
|
if( not_zeroes >= digits )
|
|
|
|
{
|
|
|
|
str[i+1] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool CorrectUrlChar(wchar_t c)
|
|
|
|
{
|
|
|
|
return (c >= 'a' && c <='z') ||
|
|
|
|
(c >= 'A' && c <='Z') ||
|
|
|
|
(c >= '0' && c <='9') ||
|
|
|
|
c == '(' || c == ')' || c == '.' || c == ',' || c == '_' || c == '-';
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-13 00:16:13 +01:00
|
|
|
|
|
|
|
// this function checks how many dots there are in the url
|
|
|
|
// if there are more than one (last) dot then the first dots will be changed into '_'
|
2010-11-21 01:19:17 +01:00
|
|
|
void CorrectUrlDots(std::wstring & url)
|
2009-12-30 21:46:12 +01:00
|
|
|
{
|
|
|
|
size_t i = url.size();
|
|
|
|
bool was_dot = false;
|
|
|
|
|
|
|
|
while( i-- > 0 )
|
|
|
|
{
|
|
|
|
if( url[i] == '.' )
|
|
|
|
{
|
|
|
|
if( was_dot )
|
|
|
|
// only one dot is allowed
|
2010-11-21 01:19:17 +01:00
|
|
|
url[i] = '_'; // !! do konfiga
|
2009-12-30 21:46:12 +01:00
|
|
|
|
|
|
|
was_dot = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
// !! pomyslec o lepszej nazwie
|
|
|
|
void CorrectUrlChars(std::wstring & url)
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring::iterator i;
|
2009-12-30 21:46:12 +01:00
|
|
|
|
2010-02-13 00:16:13 +01:00
|
|
|
for(i=url.begin(); i != url.end() ; ++i)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
if( !CorrectUrlChar(*i) )
|
|
|
|
{
|
2011-08-30 00:23:54 +02:00
|
|
|
wchar_t c = TemplatesFunctions::locale.UrlSubst(*i);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
if( CorrectUrlChar(c) )
|
|
|
|
*i = c;
|
|
|
|
else
|
2010-11-21 01:19:17 +01:00
|
|
|
*i = '_'; // !! dodac do konfiga
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
// !! pomyslec o lepszej nazwie
|
|
|
|
// przerzucic do funkcji - tam gdzie jest PrepareUrl()
|
|
|
|
// bo tutaj nie mamy wskaznika na config
|
|
|
|
void CorrectUrlOnlyAllowedChar(std::wstring & url)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2009-12-30 21:46:12 +01:00
|
|
|
CorrectUrlDots(url);
|
|
|
|
CorrectUrlChars(url);
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::to_lower_emplace(url);
|
2009-12-30 21:46:12 +01:00
|
|
|
Trim(url, '_');
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
if( url.empty() || url == L"." )
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
// !! brakuje config->
|
|
|
|
//if( config->item_url_empty.empty() )
|
2010-11-21 01:19:17 +01:00
|
|
|
url = L"unnamed";
|
2010-08-10 18:12:50 +02:00
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// url = config->item_url_empty;
|
2009-12-30 21:46:12 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
// CorrectUrlDots(url);
|
|
|
|
// CorrectUrlChars(url);
|
|
|
|
// ToSmall(url);
|
2009-12-30 21:46:12 +01:00
|
|
|
// we don't trim here and the string will not be empty
|
2010-08-10 18:12:50 +02:00
|
|
|
//}
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
2009-12-30 21:46:12 +01:00
|
|
|
if( url[0] >= '0' && url[0] <= '9' )
|
2008-12-14 06:28:28 +01:00
|
|
|
// url must begin with a letter
|
2009-12-30 21:46:12 +01:00
|
|
|
url.insert(url.begin(), '_');
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * DateToStr(int year, int month, int day)
|
2010-02-15 01:31:14 +01:00
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
|
|
|
|
static wchar_t buffer[100];
|
2010-02-15 01:31:14 +01:00
|
|
|
|
|
|
|
--month;
|
|
|
|
|
|
|
|
if( month < 0 )
|
|
|
|
month = 0;
|
|
|
|
|
|
|
|
if( month > 11 )
|
|
|
|
month = 11;
|
|
|
|
|
|
|
|
if( year == 0 )
|
2010-11-21 01:19:17 +01:00
|
|
|
swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%ls %02d", month_letter[month], day);
|
2010-02-15 01:31:14 +01:00
|
|
|
else
|
2010-11-21 01:19:17 +01:00
|
|
|
swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%02d %ls %02d", year, month_letter[month], day);
|
2010-02-15 01:31:14 +01:00
|
|
|
|
|
|
|
// warning: not thread safe (we do not use threads)
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * DateToStr(int year, int month, int day, int hour, int min, int sec)
|
2009-01-31 07:53:36 +01:00
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
static const wchar_t * month_letter[] = { L"I", L"II", L"III", L"IV", L"V", L"VI", L"VII", L"VIII", L"IX", L"X", L"XI", L"XII" };
|
|
|
|
static wchar_t buffer[100];
|
2009-01-31 07:53:36 +01:00
|
|
|
|
|
|
|
--month;
|
|
|
|
|
|
|
|
if( month < 0 )
|
2009-11-21 00:09:52 +01:00
|
|
|
month = 0;
|
2009-01-31 07:53:36 +01:00
|
|
|
|
|
|
|
if( month > 11 )
|
|
|
|
month = 11;
|
|
|
|
|
2009-03-23 00:54:15 +01:00
|
|
|
if( year == 0 )
|
2010-11-21 01:19:17 +01:00
|
|
|
swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%ls %02d %02d:%02d:%02d", month_letter[month], day, hour, min, sec);
|
2009-03-23 00:54:15 +01:00
|
|
|
else
|
2010-11-21 01:19:17 +01:00
|
|
|
swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%02d %ls %02d %02d:%02d:%02d", year, month_letter[month], day, hour, min, sec);
|
2009-01-31 07:53:36 +01:00
|
|
|
|
|
|
|
// warning: not thread safe (we do not use threads)
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 03:59:42 +02:00
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
const wchar_t * DateToStr(const pt::Date & d)
|
2010-10-24 01:12:47 +02:00
|
|
|
{
|
2012-05-27 01:04:49 +02:00
|
|
|
return DateToStr(d.year, d.month, d.day, d.hour, d.min, d.sec);
|
2010-10-24 01:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * DateToStr(time_t t)
|
2009-03-23 00:54:15 +01:00
|
|
|
{
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date date = t;
|
2009-03-23 00:54:15 +01:00
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
return DateToStr(date);
|
2009-03-23 00:54:15 +01:00
|
|
|
}
|
|
|
|
|
2009-04-16 03:59:42 +02:00
|
|
|
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
const wchar_t * DateToStrWithoutHours(const pt::Date & d)
|
2010-10-24 01:12:47 +02:00
|
|
|
{
|
2012-05-27 01:04:49 +02:00
|
|
|
return DateToStr(d.year, d.month, d.day);
|
2010-10-24 01:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * DateToStrWithoutHours(time_t t)
|
2010-07-27 22:41:56 +02:00
|
|
|
{
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date date = t;
|
2010-07-27 22:41:56 +02:00
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
return DateToStrWithoutHours(date);
|
2010-07-27 22:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 21:56:52 +01:00
|
|
|
|
2009-11-21 00:09:52 +01:00
|
|
|
// this format is used with cookies
|
|
|
|
const char * DateToStrCookie(int year, int month, int day, int hour, int min, int sec)
|
|
|
|
{
|
|
|
|
static const char * month_str[]={ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
|
|
|
static char buffer[100];
|
|
|
|
|
|
|
|
--month;
|
|
|
|
|
|
|
|
if( month < 0 )
|
|
|
|
month = 0;
|
|
|
|
|
|
|
|
if( month > 11 )
|
|
|
|
month = 11;
|
|
|
|
|
|
|
|
sprintf(buffer, "%02d-%s-%04d %02d:%02d:%02d", day, month_str[month], year, hour, min, sec);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
const char * DateToStrCookie(const pt::Date & d)
|
2010-10-24 01:12:47 +02:00
|
|
|
{
|
2012-05-27 01:04:49 +02:00
|
|
|
return DateToStrCookie(d.year, d.month, d.day, d.hour, d.min, d.sec);
|
2010-10-24 01:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 00:09:52 +01:00
|
|
|
const char * DateToStrCookie(time_t t)
|
|
|
|
{
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::Date date = t;
|
2009-11-21 00:09:52 +01:00
|
|
|
|
2012-05-27 01:04:49 +02:00
|
|
|
return DateToStrCookie(date);
|
2009-11-21 00:09:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * IpToStr(unsigned int ip_)
|
2009-04-16 03:59:42 +02:00
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
static wchar_t buffer[100];
|
2009-04-16 03:59:42 +02:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
unsigned int ip;
|
|
|
|
unsigned char c[4];
|
|
|
|
} ip;
|
|
|
|
|
|
|
|
ip.ip = ip_;
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
swprintf(buffer, sizeof(buffer)/sizeof(wchar_t), L"%u.%u.%u.%u", (int)ip.c[0], (int)ip.c[1], (int)ip.c[2], (int)ip.c[3]);
|
2009-04-16 03:59:42 +02:00
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 02:58:38 +01:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::WTextStream IPToStr(unsigned int ip)
|
2012-10-27 09:44:26 +02:00
|
|
|
{
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::WTextStream buf;
|
2012-10-27 09:44:26 +02:00
|
|
|
|
|
|
|
for(int i=0 ; i<4 ; ++i, ip >>= 8)
|
|
|
|
{
|
|
|
|
buf << (ip & 0xff);
|
|
|
|
|
|
|
|
if( i<3 )
|
|
|
|
buf << '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
pt::WTextStream IPToStr(int ip)
|
2012-10-27 09:44:26 +02:00
|
|
|
{
|
|
|
|
return IPToStr(static_cast<unsigned int>(ip));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
/*
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
by default we do not treat a new line character (10) as a white character
|
2012-02-28 22:09:44 +01:00
|
|
|
*/
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
bool IsWhite(wchar_t c, bool treat_new_line_as_white)
|
2009-06-05 22:29:06 +02:00
|
|
|
{
|
2012-02-28 22:09:44 +01:00
|
|
|
using misc_private::white_chars;
|
|
|
|
|
|
|
|
size_t len = sizeof(white_chars) / sizeof(wchar_t);
|
|
|
|
size_t o1 = 0;
|
|
|
|
size_t o2 = len - 1;
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
if( c == 10 )
|
|
|
|
return treat_new_line_as_white ? true : false;
|
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
if( c < white_chars[o1] || c > white_chars[o2] )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( c == white_chars[o1] || c == white_chars[o2] )
|
2009-06-05 22:29:06 +02:00
|
|
|
return true;
|
2012-02-28 22:09:44 +01:00
|
|
|
|
|
|
|
while( o1 + 1 < o2 )
|
|
|
|
{
|
|
|
|
size_t o = (o2 - o1)/2 + o1;
|
|
|
|
|
|
|
|
if( c == white_chars[o] )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( c > white_chars[o] )
|
|
|
|
o1 = o;
|
|
|
|
else
|
|
|
|
o2 = o;
|
|
|
|
}
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 03:59:42 +02:00
|
|
|
|
2012-09-26 09:18:32 +02:00
|
|
|
/*
|
|
|
|
return true if the whole string has only white characters
|
|
|
|
an empty string is treated as white
|
|
|
|
*/
|
|
|
|
bool IsWhite(const wchar_t * str, bool treat_new_line_as_white)
|
|
|
|
{
|
|
|
|
for( ; *str != 0 ; ++str )
|
|
|
|
{
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
if( !IsWhite(*str, treat_new_line_as_white) )
|
2012-09-26 09:18:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
return true if the whole string has only white characters
|
|
|
|
*/
|
|
|
|
bool IsWhite(const std::wstring & str, bool treat_new_line_as_white)
|
|
|
|
{
|
|
|
|
return IsWhite(str.c_str(), treat_new_line_as_white);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
void TrimWhite(std::wstring & s, bool trim_new_line_too)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if( s.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// looking for white characters at the end
|
|
|
|
for(i=s.size()-1 ; i>0 && IsWhite(s[i], trim_new_line_too) ; --i);
|
|
|
|
|
|
|
|
if( i==0 && IsWhite(s[i], trim_new_line_too) )
|
|
|
|
{
|
|
|
|
// the whole string has white characters
|
|
|
|
s.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// deleting white characters at the end
|
|
|
|
if( i != s.size() - 1 )
|
|
|
|
s.erase(i+1, std::wstring::npos);
|
|
|
|
|
|
|
|
// looking for white characters at the beginning
|
|
|
|
for(i=0 ; i<s.size() && IsWhite(s[i], trim_new_line_too) ; ++i);
|
|
|
|
|
|
|
|
// deleting white characters at the beginning
|
|
|
|
if( i != 0 )
|
|
|
|
s.erase(0, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const wchar_t * SkipWhite(const wchar_t * s, bool treat_new_line_as_white)
|
|
|
|
{
|
|
|
|
while( IsWhite(*s, treat_new_line_as_white) )
|
|
|
|
++s;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TrimFirst(std::wstring & s, wchar_t c)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if( s.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TrimLast(std::wstring & s, wchar_t c)
|
|
|
|
{
|
|
|
|
size_t 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, std::wstring::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Trim(std::wstring & s, wchar_t c)
|
|
|
|
{
|
|
|
|
if( s.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
TrimLast(s, c);
|
|
|
|
TrimFirst(s, c);
|
|
|
|
}
|
2012-09-26 09:18:32 +02:00
|
|
|
|
2012-02-28 22:09:44 +01:00
|
|
|
|
2011-07-14 01:14:10 +02:00
|
|
|
bool IsLastSlash(const std::wstring & path)
|
|
|
|
{
|
|
|
|
if( path.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return path[path.size()-1] == '/';
|
|
|
|
}
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
bool IsInt(const wchar_t * str, bool treat_new_line_as_white, bool allow_negative_value)
|
|
|
|
{
|
|
|
|
size_t digit = 0;
|
2009-06-05 22:29:06 +02:00
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
str = SkipWhite(str, treat_new_line_as_white);
|
|
|
|
|
|
|
|
if( allow_negative_value && *str == '-' )
|
|
|
|
str += 1;
|
|
|
|
|
|
|
|
while( *str>='0' && *str<='9' )
|
|
|
|
{
|
|
|
|
digit += 1;
|
|
|
|
str += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( digit == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
str = SkipWhite(str, treat_new_line_as_white);
|
|
|
|
|
|
|
|
if( *str != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInt(const wchar_t * str, bool treat_new_line_as_white)
|
2014-10-09 22:44:56 +02:00
|
|
|
{
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
return IsInt(str, treat_new_line_as_white, true);
|
2014-10-09 22:44:56 +02:00
|
|
|
}
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
|
|
|
|
bool IsInt(const std::wstring & str, bool treat_new_line_as_white)
|
2014-10-09 22:44:56 +02:00
|
|
|
{
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
return IsInt(str.c_str(), treat_new_line_as_white);
|
2014-10-09 22:44:56 +02:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
bool IsSize(const wchar_t * str, bool treat_new_line_as_white)
|
2009-12-30 21:46:12 +01:00
|
|
|
{
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
return IsInt(str, treat_new_line_as_white, false);
|
|
|
|
}
|
2010-11-21 01:19:17 +01:00
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
|
|
|
|
bool IsSize(const std::wstring & str, bool treat_new_line_as_white)
|
|
|
|
{
|
|
|
|
return IsSize(str.c_str(), treat_new_line_as_white);
|
2009-12-30 21:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
|
|
|
|
bool IsFloat(const wchar_t * str, bool treat_new_line_as_white)
|
2009-11-17 00:36:38 +01:00
|
|
|
{
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
size_t digit = 0;
|
|
|
|
size_t comma = 0;
|
2009-11-17 00:36:38 +01:00
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
str = SkipWhite(str, treat_new_line_as_white);
|
|
|
|
|
|
|
|
if( *str == '-' )
|
|
|
|
str += 1;
|
|
|
|
|
|
|
|
while( (*str == ',' || *str == '.') || (*str>='0' && *str<='9') )
|
|
|
|
{
|
|
|
|
if( *str == ',' || *str == '.' )
|
|
|
|
comma += 1;
|
|
|
|
else
|
|
|
|
digit += 1;
|
|
|
|
|
|
|
|
str += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( comma > 1 || digit == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
str = SkipWhite(str, treat_new_line_as_white);
|
|
|
|
|
|
|
|
if( *str != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsFloat(const std::wstring & str, bool treat_new_line_as_white)
|
|
|
|
{
|
|
|
|
return IsFloat(str.c_str(), treat_new_line_as_white);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Overwrite(std::string & str)
|
|
|
|
{
|
|
|
|
for(char & c : str)
|
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Overwrite(std::wstring & str)
|
|
|
|
{
|
|
|
|
for(wchar_t & c : str)
|
|
|
|
c = 0;
|
2009-11-17 00:36:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
updated: to the new Ezc API
removed statements: [if-index ...] [is ...] [is-no ...]
added: generic ezc functions:
and, any (the same as and), or, one (the same as or), not, cmp, trim
to_lower, to_upper, index
changed: in misc:
added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
(they were templates before)
added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
2014-11-02 18:47:34 +01:00
|
|
|
|
|
|
|
|
2012-03-11 17:21:52 +01:00
|
|
|
bool IsEmailCorrectChar(wchar_t c)
|
|
|
|
{
|
|
|
|
bool correct = false;
|
|
|
|
|
2012-03-09 23:56:54 +01:00
|
|
|
const wchar_t * allowed_chars = L"@.!#$%&'*+-/=?^_`{|}~";
|
|
|
|
|
|
|
|
if( (c >= 'A' && c<='Z') ||
|
|
|
|
(c >= 'a' && c<='z') ||
|
|
|
|
(c >= '0' && c<='9') )
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
2012-03-09 23:56:54 +01:00
|
|
|
correct = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(size_t a=0 ; allowed_chars[a] != 0 ; ++a)
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
2012-03-09 23:56:54 +01:00
|
|
|
if( c == allowed_chars[a] )
|
2009-10-01 00:31:20 +02:00
|
|
|
{
|
2012-03-09 23:56:54 +01:00
|
|
|
correct = true;
|
|
|
|
break;
|
2009-10-01 00:31:20 +02:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 23:56:54 +01:00
|
|
|
}
|
2012-03-11 17:21:52 +01:00
|
|
|
|
|
|
|
return correct;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-09 23:56:54 +01:00
|
|
|
bool ValidateEmail(const wchar_t * email)
|
|
|
|
{
|
|
|
|
int at = 0; // how many '@'
|
|
|
|
int dots_after_at = 0; // how many dots in the domain part
|
|
|
|
|
|
|
|
for(size_t i=0 ; email[i] != 0 ; ++i)
|
|
|
|
{
|
|
|
|
if( !IsEmailCorrectChar(email[i]) )
|
|
|
|
return false;
|
|
|
|
|
2009-10-01 00:31:20 +02:00
|
|
|
if( email[i] == '@' )
|
|
|
|
++at;
|
2012-03-09 23:56:54 +01:00
|
|
|
|
|
|
|
if( email[i] == '.' && at > 0 )
|
|
|
|
++dots_after_at;
|
2009-10-01 00:31:20 +02:00
|
|
|
}
|
|
|
|
|
2012-03-09 23:56:54 +01:00
|
|
|
if( at != 1 || dots_after_at == 0 )
|
2009-10-01 00:31:20 +02:00
|
|
|
return false;
|
|
|
|
|
2012-03-09 23:56:54 +01:00
|
|
|
return true;
|
2009-10-01 00:31:20 +02:00
|
|
|
}
|
2012-03-11 17:21:52 +01:00
|
|
|
|
|
|
|
|
2012-03-09 23:56:54 +01:00
|
|
|
bool ValidateEmail(const std::wstring & email)
|
|
|
|
{
|
2012-03-11 17:21:52 +01:00
|
|
|
return ValidateEmail(email.c_str());
|
|
|
|
}
|
|
|
|
|
2010-01-28 16:39:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool IsFile(const wchar_t * file)
|
2010-01-28 16:39:01 +01:00
|
|
|
{
|
|
|
|
struct stat sb;
|
2014-10-09 22:44:56 +02:00
|
|
|
char file_name[WINIX_OS_PATH_SIZE];
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(file, file_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
2010-01-28 16:39:01 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
return (stat(file_name, &sb) == 0);
|
2010-01-28 16:39:01 +01:00
|
|
|
}
|
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool IsFile(const std::wstring & file)
|
2010-01-28 16:39:01 +01:00
|
|
|
{
|
|
|
|
return IsFile(file.c_str());
|
|
|
|
}
|
2010-02-13 00:16:13 +01:00
|
|
|
|
|
|
|
|
2014-09-28 19:30:05 +02:00
|
|
|
/*
|
|
|
|
* group can be -1 (it is not used then)
|
|
|
|
*/
|
|
|
|
bool CreateDir(const wchar_t * dir, int priv, int group)
|
2010-02-19 00:30:22 +01:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char dir_name[WINIX_OS_PATH_SIZE];
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2010-02-19 00:30:22 +01:00
|
|
|
if( !IsFile(dir) )
|
|
|
|
{
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(dir, dir_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
if( mkdir(dir_name, 0777) < 0 )
|
2010-02-19 00:30:22 +01:00
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
//log << log1 << "Can't create a directory on fs: " << dir << logend;
|
2010-02-19 00:30:22 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-28 19:30:05 +02:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
return SetPriv(dir, priv, group);
|
2010-02-19 00:30:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-28 19:30:05 +02:00
|
|
|
bool CreateDir(const std::wstring & dir, int priv, int group)
|
2010-02-19 00:30:22 +01:00
|
|
|
{
|
2014-09-28 19:30:05 +02:00
|
|
|
return CreateDir(dir.c_str(), priv, group);
|
2010-02-19 00:30:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-15 02:47:26 +01:00
|
|
|
// creating directories (can be more than one)
|
|
|
|
// 'dirs' can begin with a slash (will be skipped)
|
2014-09-28 19:30:05 +02:00
|
|
|
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv, int group, bool skip_last)
|
2010-03-15 02:47:26 +01:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
static std::wstring temp; // !! IMPROVE ME change to char[WINIX_OS_PATH_SIZE] or just remove 'static'
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * p = dirs;
|
2010-03-15 02:47:26 +01:00
|
|
|
|
|
|
|
temp = base_dir; // we start creating from 'base_dir'
|
|
|
|
|
|
|
|
if( temp.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( temp[temp.size()-1] != '/' )
|
|
|
|
temp += '/';
|
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
// skipping slashes
|
|
|
|
for( ; *p=='/' ; ++p );
|
|
|
|
|
|
|
|
if( *p == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// taking the name
|
2010-12-10 22:07:01 +01:00
|
|
|
for( ; *p!=0 && *p!='/' ; ++p )
|
2010-03-15 02:47:26 +01:00
|
|
|
temp += *p;
|
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
if( !skip_last || *p!=0 )
|
2014-09-28 19:30:05 +02:00
|
|
|
if( !CreateDir(temp.c_str(), priv, group) )
|
2010-12-10 22:07:01 +01:00
|
|
|
return false;
|
2010-03-15 02:47:26 +01:00
|
|
|
|
|
|
|
temp += '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-28 19:30:05 +02:00
|
|
|
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv, int group, bool skip_last)
|
|
|
|
{
|
|
|
|
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv, group, skip_last);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
int GetGroupId(const wchar_t * name)
|
2014-09-28 19:30:05 +02:00
|
|
|
{
|
|
|
|
struct group gr;
|
|
|
|
struct group * result;
|
2014-10-09 22:44:56 +02:00
|
|
|
char group_name[WINIX_OS_USERNAME_SIZE];
|
2014-09-28 19:30:05 +02:00
|
|
|
char buffer[512];
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(name, group_name, WINIX_OS_USERNAME_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( getgrnam_r(group_name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
|
2014-09-28 19:30:05 +02:00
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
//log << log1 << "Misc: I cannot get the group_id for group name: " << name << logend;
|
2014-09-28 19:30:05 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* there is no such a group in /etc/group
|
|
|
|
*/
|
|
|
|
if( result == 0 )
|
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
//log << log1 << "Misc: There is no a group with name: " << name << logend;
|
2014-09-28 19:30:05 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gr.gr_gid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
int GetGroupId(const std::wstring & name)
|
2014-09-28 19:30:05 +02:00
|
|
|
{
|
|
|
|
return GetGroupId(name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setting priveleges and a group id on a file or on a directory
|
|
|
|
* group can be -1 (it is not used then)
|
|
|
|
*/
|
2014-10-09 22:44:56 +02:00
|
|
|
bool SetPriv(const wchar_t * name, int priv, int group)
|
2014-09-28 19:30:05 +02:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char file_name[WINIX_OS_PATH_SIZE];
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(name, file_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( chmod(file_name, priv) < 0 )
|
2014-09-28 19:30:05 +02:00
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
//log << log1 << "Misc: Can't set proper fs privileges on: " << name << logend;
|
2014-09-28 19:30:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( group != -1 )
|
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
if( chown(file_name, geteuid(), group) < 0 )
|
2014-09-28 19:30:05 +02:00
|
|
|
{
|
2018-11-21 12:03:53 +01:00
|
|
|
//log << log1 << "Can't set proper fs group on: " << name
|
|
|
|
// << ", group id was: " << group << logend;
|
2014-09-28 19:30:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
bool SetPriv(const std::wstring & name, int priv, int group)
|
2010-03-15 02:47:26 +01:00
|
|
|
{
|
2014-09-28 19:30:05 +02:00
|
|
|
return SetPriv(name.c_str(), priv, group);
|
2010-03-15 02:47:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-03 19:38:18 +02:00
|
|
|
bool CopyFile(FILE * in, FILE * out)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
size_t buflen = sizeof(buf)/sizeof(char);
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
len = fread(buf, 1, buflen, in);
|
|
|
|
|
|
|
|
if( len > 0 )
|
|
|
|
fwrite(buf, 1, len, out);
|
|
|
|
|
|
|
|
if( ferror(in) || ferror(out) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while( !feof(in) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool CopyFile(const wchar_t * src, const wchar_t * dst)
|
2010-06-03 19:38:18 +02:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char src_name[WINIX_OS_PATH_SIZE];
|
|
|
|
char dst_name[WINIX_OS_PATH_SIZE];
|
2010-06-03 19:38:18 +02:00
|
|
|
FILE * in, * out;
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(src, src_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(dst, dst_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
in = fopen(src_name, "rb");
|
2010-06-03 19:38:18 +02:00
|
|
|
|
|
|
|
if( !in )
|
|
|
|
return false;
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
out = fopen(dst_name, "wb");
|
2010-06-03 19:38:18 +02:00
|
|
|
|
|
|
|
if( !out )
|
|
|
|
{
|
|
|
|
fclose(in);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = CopyFile(in, out);
|
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
fclose(out);
|
2010-03-15 02:47:26 +01:00
|
|
|
|
2010-06-03 19:38:18 +02:00
|
|
|
if( res && ferror(out) )
|
|
|
|
res = false;
|
|
|
|
|
|
|
|
if( !res )
|
2014-10-09 22:44:56 +02:00
|
|
|
remove(dst_name);
|
2010-06-03 19:38:18 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool CopyFile(const std::wstring & src, const std::wstring & dst)
|
2010-06-03 19:38:18 +02:00
|
|
|
{
|
|
|
|
return CopyFile(src.c_str(), dst.c_str());
|
|
|
|
}
|
2010-03-15 02:47:26 +01:00
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
|
|
|
|
bool RemoveFile(const wchar_t * file)
|
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char file_name[WINIX_OS_PATH_SIZE];
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(file, file_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
return unlink(file_name) == 0;
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RemoveFile(const std::wstring & file)
|
|
|
|
{
|
|
|
|
return RemoveFile(file.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RenameFile(const wchar_t * from, const wchar_t * to)
|
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char from_name[WINIX_OS_PATH_SIZE];
|
|
|
|
char to_name[WINIX_OS_PATH_SIZE];
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(from, from_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
2010-11-21 01:19:17 +01:00
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(to, to_name, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return rename(from_name, to_name) == 0;
|
2010-11-21 01:19:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RenameFile(const std::wstring & from, const std::wstring & to)
|
|
|
|
{
|
|
|
|
return RenameFile(from.c_str(), to.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
bool GetUTF8File(const wchar_t * file_path, std::wstring & content, bool clear_content)
|
2011-06-24 22:53:21 +02:00
|
|
|
{
|
2014-10-09 22:44:56 +02:00
|
|
|
char file[WINIX_OS_PATH_SIZE];
|
|
|
|
std::ifstream get_file_content;
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
if( clear_content )
|
|
|
|
content.clear();
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
if( !wide_to_utf8(file_path, file, WINIX_OS_PATH_SIZE) )
|
2014-10-09 22:44:56 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
get_file_content.open(file, std::ios_base::in | std::ios_base::binary);
|
2011-06-24 22:53:21 +02:00
|
|
|
|
|
|
|
if( !get_file_content )
|
|
|
|
return false;
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
/*
|
|
|
|
* we don't report any errors when converting from UTF8 to wide characters here
|
|
|
|
*/
|
2021-05-21 00:41:27 +02:00
|
|
|
pt::utf8_to_wide(get_file_content, content);
|
2011-06-24 22:53:21 +02:00
|
|
|
get_file_content.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool clear_content)
|
|
|
|
{
|
|
|
|
return GetUTF8File(file_path.c_str(), content, clear_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
// if there is no an extension it returns a pointer to the last '\0' character
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * GetFileExt(const wchar_t * name)
|
2010-02-13 00:16:13 +01:00
|
|
|
{
|
2021-02-25 00:12:45 +01:00
|
|
|
const wchar_t * dot_ptr = nullptr;
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
for( ; *name != 0 ; ++name)
|
|
|
|
{
|
|
|
|
if( *name == '.' )
|
|
|
|
{
|
|
|
|
dot_ptr = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dot_ptr ? dot_ptr + 1 : name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrepareNewFileName(const wchar_t * src, const wchar_t * postfix, std::wstring & res, bool clear_res)
|
|
|
|
{
|
|
|
|
bool has_ext = false;
|
|
|
|
const wchar_t * ext = GetFileExt(src);
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
if( clear_res )
|
|
|
|
res.clear();
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
size_t len = ext - src;
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
if( len > 0 )
|
|
|
|
{
|
|
|
|
if( *(ext-1) == '.' )
|
|
|
|
{
|
|
|
|
len -= 1;
|
|
|
|
has_ext = true;
|
|
|
|
}
|
|
|
|
}
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
res.append(src, len);
|
|
|
|
res.append(postfix);
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
if( has_ext )
|
|
|
|
res.append(1, '.');
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-02-25 00:12:45 +01:00
|
|
|
res.append(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrepareNewFileName(const std::wstring & src, const std::wstring & postfix, std::wstring & res, bool clear_res)
|
|
|
|
{
|
|
|
|
return PrepareNewFileName(src.c_str(), postfix.c_str(), res, clear_res);
|
2010-02-13 00:16:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
int SelectFileType(const wchar_t * file_name)
|
2010-02-13 00:16:13 +01:00
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
const wchar_t * ext = GetFileExt(file_name);
|
2010-02-13 00:16:13 +01:00
|
|
|
|
|
|
|
// as an image we're using only those types which can be rendered
|
|
|
|
// by a web browser
|
2021-05-20 20:59:12 +02:00
|
|
|
if( pt::is_equal_nc(ext, L"jpg") ||
|
|
|
|
pt::is_equal_nc(ext, L"jpeg") ||
|
|
|
|
pt::is_equal_nc(ext, L"jpe") ||
|
|
|
|
pt::is_equal_nc(ext, L"pic") ||
|
|
|
|
pt::is_equal_nc(ext, L"tga") ||
|
|
|
|
pt::is_equal_nc(ext, L"gif") ||
|
|
|
|
pt::is_equal_nc(ext, L"bmp") ||
|
|
|
|
pt::is_equal_nc(ext, L"png") )
|
2010-12-10 22:07:01 +01:00
|
|
|
return WINIX_ITEM_FILETYPE_IMAGE;
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
if( pt::is_equal_nc(ext, L"pdf") ||
|
|
|
|
pt::is_equal_nc(ext, L"doc") ||
|
|
|
|
pt::is_equal_nc(ext, L"xls") ||
|
|
|
|
pt::is_equal_nc(ext, L"txt") ||
|
|
|
|
pt::is_equal_nc(ext, L"ods") ||
|
|
|
|
pt::is_equal_nc(ext, L"odt") )
|
2010-12-10 22:07:01 +01:00
|
|
|
return WINIX_ITEM_FILETYPE_DOCUMENT;
|
2010-02-13 00:16:13 +01:00
|
|
|
|
2021-05-20 20:59:12 +02:00
|
|
|
if( pt::is_equal_nc(ext, L"avi") ||
|
|
|
|
pt::is_equal_nc(ext, L"mp4") ||
|
|
|
|
pt::is_equal_nc(ext, L"flv") ||
|
|
|
|
pt::is_equal_nc(ext, L"mpg") ||
|
|
|
|
pt::is_equal_nc(ext, L"mpeg") ||
|
|
|
|
pt::is_equal_nc(ext, L"mkv") ||
|
|
|
|
pt::is_equal_nc(ext, L"wmv") )
|
2011-07-29 00:18:10 +02:00
|
|
|
return WINIX_ITEM_FILETYPE_VIDEO;
|
|
|
|
|
2010-12-10 22:07:01 +01:00
|
|
|
return WINIX_ITEM_FILETYPE_UNKNOWN;
|
2010-02-13 00:16:13 +01:00
|
|
|
}
|
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
int SelectFileType(const std::wstring & file_name)
|
|
|
|
{
|
|
|
|
return SelectFileType(file_name.c_str());
|
|
|
|
}
|
|
|
|
|
2010-10-24 01:12:47 +02:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-19 01:59:08 +01:00
|
|
|
void UrlEncode(const char * in, std::string & out, bool clear_out)
|
|
|
|
{
|
|
|
|
if( clear_out )
|
|
|
|
out.clear();
|
|
|
|
|
|
|
|
for(size_t i=0 ; in[i] != 0 ; ++i)
|
|
|
|
UrlEncode(in[i], out, false);
|
|
|
|
}
|
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
void UrlEncode(const std::string & in, std::string & out, bool clear_out)
|
|
|
|
{
|
2012-02-19 01:59:08 +01:00
|
|
|
UrlEncode(in.c_str(), out, clear_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UrlEncode(const wchar_t * in, std::string & out, bool clear_out)
|
|
|
|
{
|
|
|
|
static std::string ain;
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
pt::wide_to_utf8(in, ain);
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
if( clear_out )
|
|
|
|
out.clear();
|
|
|
|
|
2012-02-19 01:59:08 +01:00
|
|
|
for(size_t i=0 ; i < ain.size() ; ++i)
|
|
|
|
UrlEncode(ain[i], out, false);
|
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
|
2012-02-19 01:59:08 +01:00
|
|
|
|
|
|
|
void UrlEncode(const std::wstring & in, std::string & out, bool clear_out)
|
|
|
|
{
|
|
|
|
UrlEncode(in.c_str(), out, clear_out);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 01:59:08 +01:00
|
|
|
void UrlEncode(const wchar_t * in, std::wstring & out, bool clear_out)
|
2011-01-05 22:24:11 +01:00
|
|
|
{
|
|
|
|
static std::string ain;
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
pt::wide_to_utf8(in, ain);
|
2012-02-19 01:59:08 +01:00
|
|
|
|
|
|
|
if( clear_out )
|
|
|
|
out.clear();
|
|
|
|
|
|
|
|
for(size_t i=0 ; i < ain.size() ; ++i)
|
|
|
|
UrlEncode(ain[i], out, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UrlEncode(const std::wstring & in, std::wstring & out, bool clear_out)
|
|
|
|
{
|
|
|
|
UrlEncode(in.c_str(), out, clear_out);
|
2011-01-05 22:24:11 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 12:54:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-09 22:44:56 +02:00
|
|
|
bool UrlDecodeFromHex(int c, int & out)
|
|
|
|
{
|
|
|
|
if( c>='0' && c<='9' )
|
|
|
|
{
|
|
|
|
out = c - '0';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( c>='a' && c<='f' )
|
|
|
|
{
|
|
|
|
out = c - 'a' + 10;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( c>='A' && c<='F' )
|
|
|
|
{
|
|
|
|
out = c - 'A' + 10;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
out = 0;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UrlDecode(const char * url, std::wstring & out, bool clear_out)
|
|
|
|
{
|
|
|
|
char url_utf8[WINIX_URL_MAX_SIZE];
|
|
|
|
size_t index = 0;
|
|
|
|
int c1, c2;
|
|
|
|
|
|
|
|
if( clear_out )
|
|
|
|
out.clear();
|
|
|
|
|
|
|
|
while( *url && index < WINIX_URL_MAX_SIZE-1 )
|
|
|
|
{
|
|
|
|
if( *url == '%' && *(url+1) && *(url+2) &&
|
|
|
|
UrlDecodeFromHex(*(url+1), c1) && UrlDecodeFromHex(*(url+2), c2) )
|
|
|
|
{
|
|
|
|
url_utf8[index++] = (c1 << 4) + c2;
|
|
|
|
url += 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
url_utf8[index++] = *url;
|
|
|
|
url += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
url_utf8[index] = 0;
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
return pt::utf8_to_wide(url_utf8, out, false);
|
2014-10-09 22:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool UrlDecode(const std::string & url, std::wstring & out, bool clear_out)
|
|
|
|
{
|
|
|
|
return UrlDecode(url.c_str(), out, clear_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 01:59:08 +01:00
|
|
|
|
2012-07-10 18:50:59 +02:00
|
|
|
void QEncode(const std::wstring & in, std::string & out, bool clear)
|
2011-01-25 12:54:46 +01:00
|
|
|
{
|
2012-07-10 18:50:59 +02:00
|
|
|
using namespace misc_private;
|
2011-01-25 12:54:46 +01:00
|
|
|
|
2012-07-10 18:50:59 +02:00
|
|
|
tmp_qencode.clear();
|
|
|
|
QEncode(in, tmp_qencode);
|
|
|
|
tmp_qencode.to_string(out, clear);
|
|
|
|
tmp_qencode.clear();
|
2011-01-25 12:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-07 00:47:34 +02:00
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
/*
|
|
|
|
deleting all post temporary files
|
|
|
|
*/
|
|
|
|
void RemovePostFileTmp(PostFileTab & post_file_tab)
|
|
|
|
{
|
|
|
|
PostFileTab::iterator i = post_file_tab.begin();
|
2011-06-07 00:47:34 +02:00
|
|
|
|
2011-06-24 22:53:21 +02:00
|
|
|
for( ; i != post_file_tab.end() ; ++i )
|
|
|
|
{
|
|
|
|
const std::wstring & tmp_filename = i->second.tmp_filename;
|
|
|
|
|
|
|
|
if( !tmp_filename.empty() && RemoveFile(tmp_filename) )
|
2018-11-21 12:03:53 +01:00
|
|
|
{
|
|
|
|
//log << log3 << "Deleted tmp file: " << tmp_filename << logend;
|
|
|
|
}
|
2011-06-24 22:53:21 +02:00
|
|
|
}
|
|
|
|
}
|
2011-06-07 00:47:34 +02:00
|
|
|
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
bool wide_to_utf8(const wchar_t * wide_string, char * utf8, size_t utf8_size)
|
2014-10-09 22:44:56 +02:00
|
|
|
{
|
2021-05-21 00:41:27 +02:00
|
|
|
bool res = pt::wide_to_utf8(wide_string, utf8, utf8_size);
|
2014-10-09 22:44:56 +02:00
|
|
|
|
|
|
|
if( !res )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* either the 'utf8' buffer is too small or there was an error when converting
|
|
|
|
*/
|
2018-11-21 12:03:53 +01:00
|
|
|
//log << log1 << "Misc: I cannot convert from a wide string to an UTF-8 string, original string was: "
|
|
|
|
// << wide_string << logend;
|
2014-10-09 22:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-21 00:41:27 +02:00
|
|
|
bool wide_to_utf8(const std::wstring & wide_string, char * utf8, size_t utf8_size)
|
2014-10-09 22:44:56 +02:00
|
|
|
{
|
2021-05-21 00:41:27 +02:00
|
|
|
return wide_to_utf8(wide_string.c_str(), utf8, utf8_size);
|
2014-10-09 22:44:56 +02:00
|
|
|
}
|
2011-06-07 00:47:34 +02:00
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|