init repo

This commit is contained in:
nikolay ivanov
2014-07-05 18:22:49 +00:00
commit a8be6b9e72
17348 changed files with 9229832 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "DateTime.h"
#include "time.h"
DateTime::DateTime()
{
time_t oNow;
tm oLocal;
time( &oNow );
localtime_s( &oLocal, &oNow );
m_nYear = oLocal.tm_year + 1900;
m_nMonth = oLocal.tm_mon + 1;
m_nDay = oLocal.tm_mday;
m_nHour = oLocal.tm_hour;
m_nMinute = oLocal.tm_min;
m_nSecond = oLocal.tm_sec;
m_nMillisecond = 0;
}
DateTime::DateTime(const CString &sValue, const CString &sPattern)
:
m_nYear ( ParseValue( sValue, sPattern, "%YYYY") ),
m_nMonth ( ParseValue( sValue, sPattern, "%MM" ) ),
m_nDay ( ParseValue( sValue, sPattern, "%DD" ) ),
m_nHour ( ParseValue( sValue, sPattern, "%hh" ) ),
m_nMinute ( ParseValue( sValue, sPattern, "%mm" ) ),
m_nSecond ( ParseValue( sValue, sPattern, "%ss" ) ),
m_nMillisecond ( ParseValue( sValue, sPattern, "%ms" ) )
{
}
const CString DateTime::ToString (const CString &sPattern) const
{
CString sResult = sPattern, sTemp;
sTemp.Format( _T("%04d"), m_nYear ); sResult.Replace( _T("%YYYY"), sTemp ); sTemp.Empty();
sTemp.Format( _T("%02d"), m_nMonth ); sResult.Replace( _T("%MM"), sTemp ); sTemp.Empty();
sTemp.Format( _T("%02d"), m_nDay ); sResult.Replace( _T("%DD"), sTemp ); sTemp.Empty();
sTemp.Format( _T("%02d"), m_nHour ); sResult.Replace( _T("%hh"), sTemp ); sTemp.Empty();
sTemp.Format( _T("%02d"), m_nMinute ); sResult.Replace( _T("%mm"), sTemp ); sTemp.Empty();
sTemp.Format( _T("%02d"), m_nSecond ); sResult.Replace( _T("%ss"), sTemp ); sTemp.Empty();
sTemp.Format( _T("%02d"), m_nMillisecond ); sResult.Replace( _T("%ms"), sTemp );
return sResult;
}
const DateTime DateTime::Parse (const CString &sValue, const CString &sPattern)
{
return DateTime( sValue, sPattern );
}
const int DateTime::ParseValue(const CString &sValue, const CString &sPattern, const CString &sElement)
{
const int nPos = sPattern.Find( sElement );
if ( -1 != nPos )
{
int nSepCount = 0;
for ( int nIndex = 0; nIndex < nPos; nIndex++ )
{
if ( '%' == sPattern[nIndex] )
nSepCount++;
}
const CString sNumeric = sValue.Mid( nPos - nSepCount , sElement.GetLength() - 1 );
return _wtoi( sNumeric );
}
return 0;
}

View File

@@ -0,0 +1,66 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#ifndef UTILITY_DATE_TIME_INCLUDE_H_
#define UTILITY_DATE_TIME_INCLUDE_H_
#include "../Base/Base.h"
class DateTime
{
public:
DateTime();
DateTime(const CString& sValue, const CString &sPattern);
public:
const CString ToString(const CString &sPattern) const;
static const DateTime Parse (const CString &sValue, const CString &sPattern);
static const int ParseValue(const CString &sValue, const CString &sPattern, const CString &sElement);
private:
int m_nYear;
int m_nMonth;
int m_nDay;
int m_nHour;
int m_nMinute;
int m_nSecond;
int m_nMillisecond;
};
#endif // UTILITY_DATE_TIME_INCLUDE_H_

View File

@@ -0,0 +1,104 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "Encoding.h"
#include "Utility.h"
#include "X:\AVS\Sources\AVSOfficeStudio\Common\DocxFormat\Source\Common\SimpleTypes_Word.h"
__forceinline const CStringA Encoding::ansi2utf8 (const CStringA &sLine)
{
return wstring2string( string2wstring( sLine, CP_ACP ), CP_UTF8 );
}
__forceinline const CStringW Encoding::ansi2unicode (const CStringA &sLine)
{
return string2wstring( sLine, CP_ACP );
}
__forceinline const CStringA Encoding::utf82ansi (const CStringA &sLine)
{
return wstring2string( string2wstring( sLine, CP_UTF8 ), CP_ACP );
}
__forceinline const CStringW Encoding::utf82unicode (const CStringA &sLine)
{
return string2wstring( sLine, CP_UTF8 );
}
__forceinline const CStringA Encoding::unicode2ansi (const CStringW &sLine)
{
return wstring2string( sLine, CP_ACP );
}
__forceinline const CStringA Encoding::unicode2utf8 (const CStringW &sLine)
{
return wstring2string( sLine, CP_UTF8 );
}
__forceinline const CStringA Encoding::wstring2string(const CStringW &sLine, const unsigned int unCodePage)
{
const int nSize = WideCharToMultiByte( unCodePage, 0, sLine.GetString(), sLine.GetLength(), NULL, 0, NULL, NULL );
char *sTemp = new char[nSize];
if ( !sTemp )
return "";
WideCharToMultiByte( unCodePage, 0, sLine.GetString(), sLine.GetLength(), sTemp, nSize, NULL, NULL );
CStringA sResult( sTemp );
delete []sTemp;
return sResult;
}
__forceinline const CStringW Encoding::string2wstring(const CStringA &sLine, const unsigned int unCodePage)
{
const int nSize = MultiByteToWideChar( unCodePage, 0, sLine.GetString(), sLine.GetLength(), NULL, 0 );
wchar_t *sTemp = new wchar_t[nSize];
if ( !sTemp )
return _T("");
MultiByteToWideChar( unCodePage, 0, sLine.GetString(), sLine.GetLength(), sTemp, nSize );
CStringW sResult( sTemp );
delete []sTemp;
return sResult;
}

View File

@@ -0,0 +1,55 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#ifndef UTILITY_ENCODING_INCLUDE_H_
#define UTILITY_ENCODING_INCLUDE_H_
#include "../Base/Base.h"
class Encoding
{
public:
static __forceinline const CStringA ansi2utf8 (const CStringA &sLine);
static __forceinline const CStringW ansi2unicode(const CStringA &sLine);
static __forceinline const CStringA utf82ansi (const CStringA &sLine);
static __forceinline const CStringW utf82unicode(const CStringA &sLine);
static __forceinline const CStringA unicode2ansi(const CStringW &sLine);
static __forceinline const CStringA unicode2utf8(const CStringW &sLine);
private:
static __forceinline const CStringA wstring2string(const CStringW &sLine, const unsigned int unCodePage);
static __forceinline const CStringW string2wstring(const CStringA &sLine, const unsigned int unCodePage);
};
#endif // UTILITY_ENCODING_INCLUDE_H_

View File

@@ -0,0 +1,358 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifdef _HTML_FILE
#include "TxtFile.h"
#include "Encoding.h"
#include "Utility.h"
#include <boost/foreach.hpp>
#include "codecvt.h"
#include <streambuf>
#include <boost/algorithm/string/erase.hpp>
static const std::string BadSymbols = "\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19";
TxtFile::TxtFile(const boost::filesystem::wpath& path)
: m_path(path)
{
}
const std::list<std::string> TxtFile::readAnsi() const
{
std::ifstream file(m_path.string().c_str());
if (file.bad())
throw log_runtime_error("can't open text file");
std::list<std::string> result;
while (!file.eof())
{
std::string str;
std::getline(file, str);
size_t pos = str.find_first_of(BadSymbols);
while(pos != str.npos)
{
str.erase(pos, 1);
pos = str.find_first_of(BadSymbols, pos);
}
result.push_back(str);
}
return result;
}
const std::list<std::wstring> TxtFile::readUnicode() const
{
std::wifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
file.imbue(std::locale(std::locale(), new ucs2_conversion()));
std::list<std::wstring> result;
while (!file.eof())
{
std::wstring str;
file.ignore();
std::getline(file, str, L'\x0D');
result.push_back(str);
}
return result;
}
const std::list<std::wstring> TxtFile::readUnicodeWithOutBOM() const
{
std::wifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
file.imbue(std::locale(std::locale(), new ucs2_conversion()));
std::list<std::wstring> result;
while (!file.eof())
{
std::wstring str;
std::getline(file, str, L'\x0D');
file.ignore();
result.push_back(str);
}
return result;
}
const std::list<std::wstring> TxtFile::readBigEndian() const
{
std::wifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
file.imbue(std::locale(std::locale(), new ube_conversion()));
std::list<std::wstring> result;
while (!file.eof())
{
std::wstring str;
file.ignore();
std::getline(file, str, L'\x0D');
result.push_back(str);
}
return result;
}
const std::list<std::string> TxtFile::readUtf8() const
{
std::ifstream file(m_path.string().c_str());
if (file.bad())
throw log_runtime_error("can't open text file");
std::list<std::string> result;
file.ignore(3);
while (!file.eof())
{
std::string str;
std::getline(file, str);
result.push_back(str);
}
return result;
}
const std::list<std::string> TxtFile::readUtf8withoutPref() const
{
std::ifstream file(m_path.string().c_str());
if (file.bad())
throw log_runtime_error("can't open text file");
std::list<std::string> result;
while (!file.eof())
{
std::string str;
std::getline(file, str);
result.push_back(str);
}
return result;
}
void TxtFile::writeAnsi(const std::list<std::string>& content) const
{
setAnsiStamp();
std::ofstream file(m_path.string().c_str());
if (file.bad())
throw log_runtime_error("can't create text file");
BOOST_FOREACH(const std::string& line, content)
{
file << line << std::endl;
}
}
void TxtFile::writeUnicode(const std::list<std::wstring>& content) const
{
setUnicodeStamp();
std::wofstream file(m_path.string().c_str(), std::ios_base::binary | std::ios_base::app);
if (file.bad())
throw log_runtime_error("can't create text file");
file.imbue(std::locale(std::locale(), new ucs2_conversion()));
BOOST_FOREACH(const std::wstring& line, content)
{
file << line << L'\x0D' << L'\x0A';
}
}
void TxtFile::writeBigEndian(const std::list<std::wstring>& content) const
{
setBigEndianStamp();
std::wofstream file(m_path.string().c_str(), std::ios_base::binary | std::ios_base::app);
if (file.bad())
throw log_runtime_error("can't create text file");
file.imbue(std::locale(std::locale(), new ube_conversion()));
BOOST_FOREACH(const std::wstring& line, content)
{
file << line << L'\x0D' << L'\x0A';
}
}
void TxtFile::writeUtf8(const std::list<std::string>& content) const
{
setUtf8Stamp();
std::ofstream file(m_path.string().c_str(), std::ios_base::app);
if (file.bad())
throw log_runtime_error("can't create text file");
BOOST_FOREACH(const std::string& line, content)
{
file << line << std::endl;
}
}
void TxtFile::writeUtf8withoutPref(const std::list<std::string>& content) const
{
std::ofstream file(m_path.string().c_str());
if (file.bad())
throw log_runtime_error("can't create text file");
BOOST_FOREACH(const std::string& line, content)
{
file << line << std::endl;
}
}
const bool TxtFile::isAnsi() const
{
return true;
}
const bool TxtFile::isUnicode() const
{
std::ifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
char symbol;
file >> symbol;
if (symbol != '\xFF')
return false;
file >> symbol;
if (symbol != '\xFE')
return false;
return true;
}
const bool TxtFile::isUnicodeWithOutBOM() const
{
std::ifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
std::string str;
std::getline(file, str, '\x0A');
bool bUnicode = (str.find('\x0') != str.npos);
return bUnicode;
}
const bool TxtFile::isBigEndian() const
{
std::ifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
char symbol;
file >> symbol;
if (symbol != '\xFE')
return false;
file >> symbol;
if (symbol != '\xFF')
return false;
return true;
}
const bool TxtFile::isUtf8() const
{
std::ifstream file(m_path.string().c_str(), std::ios_base::binary);
if (file.bad())
throw log_runtime_error("can't open text file");
char symbol;
file >> symbol;
if (symbol != '\xEF')
return false;
file >> symbol;
if (symbol != '\xBB')
return false;
file >> symbol;
if (symbol != '\xBF')
return false;
return true;
}
void TxtFile::setAnsiStamp() const
{
}
void TxtFile::setUnicodeStamp() const
{
std::wofstream file(m_path.string().c_str(), std::ios_base::binary);
file << '\xFF' << '\xFE';
}
void TxtFile::setBigEndianStamp() const
{
std::wofstream file(m_path.string().c_str(), std::ios_base::binary);
file << '\xFE' << '\xFF';
}
void TxtFile::setUtf8Stamp() const
{
std::wofstream file(m_path.string().c_str(), std::ios_base::binary);
file << '\xEF' << '\xBB' << '\xBF';
}
#endif

View File

@@ -0,0 +1,82 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#ifndef UTILITY_TXT_FILE_INCLUDE_H_
#define UTILITY_TXT_FILE_INCLUDE_H_
#ifdef _HTML_FILE
#include <boost/filesystem.hpp>
#include <string>
#include <list>
class TxtFile
{
public:
TxtFile(const boost::filesystem::wpath& path);
public:
const std::list<std::string> readAnsi() const;
const std::list<std::wstring> readUnicode() const;
const std::list<std::wstring> readUnicodeWithOutBOM() const;
const std::list<std::wstring> readBigEndian() const;
const std::list<std::string> readUtf8() const;
const std::list<std::string> readUtf8withoutPref() const;
public:
void writeAnsi(const std::list<std::string>& content) const;
void writeUnicode(const std::list<std::wstring>& content) const;
void writeBigEndian(const std::list<std::wstring>& content) const;
void writeUtf8(const std::list<std::string>& content) const;
void writeUtf8withoutPref(const std::list<std::string>& content) const;
public:
const bool isAnsi() const;
const bool isUnicode() const;
const bool isUnicodeWithOutBOM() const;
const bool isBigEndian() const;
const bool isUtf8() const;
private:
void setAnsiStamp() const;
void setUnicodeStamp() const;
void setBigEndianStamp() const;
void setUtf8Stamp() const;
private:
boost::filesystem::wpath m_path;
};
#endif
#endif // UTILITY_TXT_FILE_INCLUDE_H_

View File

@@ -0,0 +1,388 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#ifndef _UNIT_INCLUDE_H_
#define _UNIT_INCLUDE_H_
AVSINLINE double Cm_To_Mm (const double &dValue)
{
return dValue * 10;
}
AVSINLINE double Cm_To_Pt (const double &dValue)
{
return dValue * 72 / 2.54;
}
AVSINLINE double Cm_To_Px (const double &dValue)
{
return dValue * 72 * 4 / 3 / 2.54;
}
AVSINLINE double Cm_To_Inch (const double &dValue)
{
return dValue / 2.54;
}
AVSINLINE double Cm_To_Dx (const double &dValue)
{
return dValue * 72 * 20 / 2.54;
}
AVSINLINE double Cm_To_Sx (const double &dValue)
{
return dValue * 72 * 100 * 1000 / 20;
}
AVSINLINE double Cm_To_Multi (const double &dValue)
{
return dValue * 72 * 20 / 2.54;
}
AVSINLINE double Cm_To_Emu (const double &dValue)
{
return dValue * 360000;
}
AVSINLINE double Mm_To_Cm (const double &dValue)
{
return dValue / 10;
}
AVSINLINE double Mm_To_Pt (const double &dValue)
{
return dValue * 72 / 10 / 2.54;
}
AVSINLINE double Mm_To_Px (const double &dValue)
{
return dValue * 72 * 4 / 3 / 10 / 2.54;
}
AVSINLINE double Mm_To_Inch (const double &dValue)
{
return dValue / 2.54 / 10;
}
AVSINLINE double Mm_To_Dx (const double &dValue)
{
return dValue * 72 * 20 / 10 / 2.54;
}
AVSINLINE double Mm_To_Sx (const double &dValue)
{
return dValue * 72 * 100 * 1000 / 10 / 20;
}
AVSINLINE double Mm_To_Multi (const double &dValue)
{
return dValue * 72 * 20 / 10 / 2.54;
}
AVSINLINE double Mm_To_Emu (const double &dValue)
{
return dValue * 36000;
}
AVSINLINE double Pt_To_Cm (const double &dValue)
{
return dValue * 2.54 / 72;
}
AVSINLINE double Pt_To_Mm (const double &dValue)
{
return dValue * 2.54 * 10 / 72;
}
AVSINLINE double Pt_To_Px (const double &dValue)
{
return dValue * 4 / 3;
}
AVSINLINE double Pt_To_Inch (const double &dValue)
{
return dValue / 72;
}
AVSINLINE double Pt_To_Dx (const double &dValue)
{
return dValue * 20;
}
AVSINLINE double Pt_To_Sx (const double &dValue)
{
return dValue * 2.54 * 100 * 1000 / 20;
}
AVSINLINE double Pt_To_Multi (const double &dValue)
{
return dValue * 20;
}
AVSINLINE double Pt_To_Emu (const double &dValue)
{
return dValue * 12700;
}
AVSINLINE double Px_To_Cm (const double &dValue)
{
return dValue * 2.54 * 3/ 72 / 4;
}
AVSINLINE double Px_To_Mm (const double &dValue)
{
return dValue * 2.54 * 10 * 3/ 72 /4;
}
AVSINLINE double Px_To_Pt (const double &dValue)
{
return dValue * 3 / 4;
}
AVSINLINE double Px_To_Inch (const double &dValue)
{
return dValue * 3 / 72 / 4;
}
AVSINLINE double Px_To_Dx (const double &dValue)
{
return dValue * 20 * 3 / 4;
}
AVSINLINE double Px_To_Sx (const double &dValue)
{
return dValue * 2.54 * 100 * 1000 * 3/ 20 / 4;
}
AVSINLINE double Px_To_Multi (const double &dValue)
{
return dValue * 20 * 3 / 4;
}
AVSINLINE double Px_To_Emu (const double &dValue)
{
return dValue * 9525;
}
AVSINLINE double Inch_To_Cm (const double &dValue)
{
return dValue * 2.54;
}
AVSINLINE double Inch_To_Mm (const double &dValue)
{
return dValue * 2.54 * 10;
}
AVSINLINE double Inch_To_Pt (const double &dValue)
{
return dValue * 72;
}
AVSINLINE double Inch_To_Px (const double &dValue)
{
return dValue * 72 * 4 / 3;
}
AVSINLINE double Inch_To_Dx (const double &dValue)
{
return dValue * 72 * 20;
}
AVSINLINE double Inch_To_Sx (const double &dValue)
{
return dValue * 1000 * 100 * 2.54 * 72 / 20;
}
AVSINLINE double Inch_To_Multi(const double &dValue)
{
return dValue * 72 * 20;
}
AVSINLINE double Inch_To_Emu (const double &dValue)
{
return dValue * 914400;
}
AVSINLINE double Dx_To_Cm (const double &dValue)
{
return dValue * 2.54 / 72 / 20;
}
AVSINLINE double Dx_To_Mm (const double &dValue)
{
return dValue * 2.54 * 10 / 72 / 20;
}
AVSINLINE double Dx_To_Pt (const double &dValue)
{
return dValue / 20;
}
AVSINLINE double Dx_To_Px (const double &dValue)
{
return dValue * 4 / 3 / 20;
}
AVSINLINE double Dx_To_Inch (const double &dValue)
{
return dValue / 20 / 72;
}
AVSINLINE double Dx_To_Sx (const double &dValue)
{
return dValue * 635;
}
AVSINLINE double Dx_To_Multi (const double &dValue)
{
return dValue;
}
AVSINLINE double Dx_To_Emu (const double &dValue)
{
return dValue * 635;
}
AVSINLINE double Sx_To_Cm (const double &dValue)
{
return dValue * 20 / 72 / 100 / 1000;
}
AVSINLINE double Sx_To_Mm (const double &dValue)
{
return dValue * 20 / 72 / 100 / 1000 * 10;
}
AVSINLINE double Sx_To_Pt (const double &dValue)
{
return dValue * 20 / 100 / 1000 / 2.54;
}
AVSINLINE double Sx_To_Px (const double &dValue)
{
return dValue * 20 * 4 / 3 / 100 / 1000 / 2.54;
}
AVSINLINE double Sx_To_Inch (const double &dValue)
{
return dValue * 20 / 2.54 / 72 / 100 / 1000;
}
AVSINLINE double Sx_To_Dx (const double &dValue)
{
return dValue * 20 * 20 / 2.54 / 100 / 1000;
}
AVSINLINE double Sx_To_Multi (const double &dValue)
{
return dValue * 20 * 20 / 2.54 / 100 / 1000;
}
AVSINLINE double Sx_To_Emu (const double &dValue)
{
return dValue;
}
AVSINLINE double Multi_To_Cm (const double &dValue)
{
return dValue * 2.54 / 72 / 20;
}
AVSINLINE double Multi_To_Mm (const double &dValue)
{
return dValue * 2.54 * 10 / 72 / 20;
}
AVSINLINE double Multi_To_Pt (const double &dValue)
{
return dValue / 20;
}
AVSINLINE double Multi_To_Px (const double &dValue)
{
return dValue * 4 / 3 / 20;
}
AVSINLINE double Multi_To_Inch(const double &dValue)
{
return dValue / 20 / 72;
}
AVSINLINE double Multi_To_Sx (const double &dValue)
{
return dValue * 635;
}
AVSINLINE double Multi_To_Dx (const double &dValue)
{
return dValue;
}
AVSINLINE double Multi_To_Emu (const double &dValue)
{
return dValue * 635;
}
AVSINLINE double Emu_To_Cm (const double &dValue)
{
return dValue / 360000;
}
AVSINLINE double Emu_To_Mm (const double &dValue)
{
return dValue / 36000;
}
AVSINLINE double Emu_To_Pt (const double &dValue)
{
return dValue / 12700;
}
AVSINLINE double Emu_To_Px (const double &dValue)
{
return dValue / 9525;
}
AVSINLINE double Emu_To_Inch (const double &dValue)
{
return dValue / 914400;
}
AVSINLINE double Emu_To_Sx (const double &dValue)
{
return dValue;
}
AVSINLINE double Emu_To_Dx (const double &dValue)
{
return dValue / 635;
}
AVSINLINE double Emu_To_Multi (const double &dValue)
{
return dValue / 635;
}
#endif // _UNIT_INCLUDE_H_

View File

@@ -0,0 +1,73 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#ifndef UTILITY_UTILITY_INCLUDE_H_
#define UTILITY_UTILITY_INCLUDE_H_
#include "DateTime.h"
#include "Unit.h"
#include "Encoding.h"
#ifdef _HTML_FILE
#include "TxtFile.h"
#include <string>
#include <vector>
#include <list>
#include <boost/foreach.hpp>
template<typename Out, typename In>
static const std::vector<Out> transform(const std::vector<In>& lines, const Out(*func)(const In&))
{
std::vector<Out> result;
BOOST_FOREACH(const In& line, lines)
{
result.push_back(func(line));
}
return result;
}
template<typename Out, typename In>
static const std::list<Out> transform(const std::list<In>& lines, const Out(*func)(const In&))
{
std::list<Out> result;
BOOST_FOREACH(const In& line, lines)
{
result.push_back(func(line));
}
return result;
}
#endif
#endif // UTILITY_UTILITY_INCLUDE_H_

View File

@@ -0,0 +1,225 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "codecvt.h"
using namespace std;
ucs2_conversion::result
ucs2_conversion::do_in(mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const
{
const int max_input = (from_end - from) & ~1;
const int max_output = (to_limit - to);
int count = min(max_input / 2, max_output);
from_next = from;
to_next = to;
for (;count--; from_next += 2, ++to_next)
{
unsigned char c1 = *from_next;
unsigned char c2 = *(from_next + 1);
*to_next = c1 | c2 << 8;
}
if (to_next == to && from_next == from_end - 1)
return partial;
return ok;
}
ucs2_conversion::result
ucs2_conversion::do_out(mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const
{
const int max_input = (from_end - from);
const int max_output = (to_limit - to) & ~1;
int count = min(max_input, max_output / 2);
from_next = from;
to_next = to;
for (;count--; ++from_next, to_next += 2)
{
*(to_next + 0) = *from_next & 0xFF;
*(to_next + 1) = *from_next >> 8 & 0xFF;
}
return ok;
}
ube_conversion::result
ube_conversion::do_in(mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const
{
const int max_input = (from_end - from) & ~1;
const int max_output = (to_limit - to);
int count = min(max_input / 2, max_output);
from_next = from;
to_next = to;
for (;count--; from_next += 2, ++to_next)
{
unsigned char c1 = *from_next;
unsigned char c2 = *(from_next + 1);
*to_next = c2 | c1 << 8;
}
if (to_next == to && from_next == from_end - 1)
return partial;
return ok;
}
ube_conversion::result
ube_conversion::do_out(mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const
{
const int max_input = (from_end - from);
const int max_output = (to_limit - to) & ~1;
int count = min(max_input, max_output / 2);
from_next = from;
to_next = to;
for (;count--; ++from_next, to_next += 2)
{
*(to_next + 1) = *from_next & 0xFF;
*(to_next + 0) = *from_next >> 8 & 0xFF;
}
return ok;
}
utf8_conversion::result
utf8_conversion::do_in(mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const
{
from_next = from;
to_next = to;
for(; to_next < to_limit && from_next < from_end; ++to_next)
{
if (static_cast<unsigned char>(*from_next) < 0x80)
{
*to_next = static_cast<unsigned char>(*from_next++);
}
else
{
const int zero_bit_pos = most_signifant_bit_position(~*from_next);
int extra_bytes = 7 - zero_bit_pos;
if (from_end - from_next < extra_bytes + 1)
return partial;
*to_next = static_cast<unsigned char>(*from_next++) & ((1 << zero_bit_pos - 1) - 1);
for (;extra_bytes--; ++from_next)
{
*to_next = *to_next << 6 | static_cast<unsigned char>(*from_next) & 63;
}
}
}
return ok;
}
utf8_conversion::result
utf8_conversion::do_out(mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const
{
from_next = from;
to_next = to;
for (;from_next < from_end; ++from_next)
{
const unsigned symbol = *from_next;
if (symbol < 0x7F)
{
if (to_next < to_limit)
*to_next++ = static_cast<unsigned char>(symbol);
else
return ok;
}
else
{
const size_t msb_pos = most_signifant_bit_position(symbol);
int extra_bytes = msb_pos / 6;
if (to_limit - to_next >= extra_bytes + 1)
{
*to_next = static_cast<unsigned char>(0xFF80 >> extra_bytes);
*to_next++ |= take_6_bits(symbol, extra_bytes * 6);
for(;extra_bytes--;)
*to_next++ = 0x80 | take_6_bits(symbol, extra_bytes * 6);
}
else
{
return ok;
}
}
}
return ok;
}
const unsigned char
utf8_conversion::take_6_bits(const int unsigned value, const size_t right_position) const
{
return (value >> right_position) & 63;
}
const size_t
utf8_conversion::most_signifant_bit_position(const unsigned int value) const
{
size_t result = 0;
size_t half = 16;
for(; half > 0; half >>= 1)
{
if (1u << (result + half) <= value )
result += half;
}
return result + 1;
}

View File

@@ -0,0 +1,101 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#ifndef UTILITY_CODECVT_INCLUDE_H_
#define UTILITY_CODECVT_INCLUDE_H_
#include <locale>
class ucs2_conversion : public std::codecvt<wchar_t, char, std::mbstate_t>
{
protected:
result do_in(std::mbstate_t& state,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
result do_out(std::mbstate_t& state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const;
bool do_always_noconv() const throw() { return false; }
int do_encoding() const throw() { return 2; }
};
class ube_conversion : public std::codecvt<wchar_t, char, std::mbstate_t>
{
protected:
result do_in(std::mbstate_t& state,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
result do_out(std::mbstate_t& state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const;
bool do_always_noconv() const throw() { return false; }
int do_encoding() const throw() { return 2; }
};
class utf8_conversion : public std::codecvt<wchar_t, char, std::mbstate_t>
{
protected:
result do_in(std::mbstate_t& state,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
result in(std::mbstate_t& state,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_limit, wchar_t*& to_next) const;
result do_out(std::mbstate_t& state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const;
result out(std::mbstate_t& state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_limit, char*& to_next) const;
bool do_always_noconv() const throw() { return false; }
int do_encoding() const throw() { return 2; }
private:
const unsigned char take_6_bits(const unsigned int value, const size_t right_position) const;
const size_t most_signifant_bit_position(const unsigned int value) const;
};
#endif // UTILITY_CODECVT_INCLUDE_H_