139 lines
2.2 KiB
C++
139 lines
2.2 KiB
C++
|
/*
|
||
|
* This file is a part of CMSLU -- Content Management System like Unix
|
||
|
* and is not publicly distributed
|
||
|
*
|
||
|
* Copyright (c) 2008, Tomasz Sowa
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include "misc.h"
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
void ToString(std::string & s, int value)
|
||
|
{
|
||
|
static char buffer[50];
|
||
|
|
||
|
sprintf(buffer, "%d", value);
|
||
|
s = buffer;
|
||
|
}
|
||
|
|
||
|
|
||
|
void ToString(std::string & s, long value)
|
||
|
{
|
||
|
static char buffer[50];
|
||
|
|
||
|
sprintf(buffer, "%ld", value);
|
||
|
s = buffer;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void SetUrlSubjectFromSubject(Item & item)
|
||
|
{
|
||
|
std::string::iterator i;
|
||
|
|
||
|
item.url_subject.clear();
|
||
|
|
||
|
for(i = item.subject.begin(); i!=item.subject.end() ; ++i)
|
||
|
{
|
||
|
int c = ChangeLocalChar(*i);
|
||
|
|
||
|
if( (c >= 'a' && c <='z') ||
|
||
|
(c >= 'A' && c <='Z') ||
|
||
|
(c >= '0' && c <='9') ||
|
||
|
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
|
||
|
)
|
||
|
{
|
||
|
item.url_subject += c;
|
||
|
}
|
||
|
else
|
||
|
item.url_subject += '_';
|
||
|
}
|
||
|
|
||
|
if( item.url_subject.empty() )
|
||
|
item.url_subject = "bez_nazwy";
|
||
|
else
|
||
|
if( item.url_subject[0] >= '0' && item.url_subject[0] <= '9' )
|
||
|
// url_subject must begin with a letter
|
||
|
item.url_subject.insert(item.url_subject.begin(), '_');
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
int polish_letters_simple[] =
|
||
|
{ 'a', 'A',
|
||
|
'c', 'C',
|
||
|
's', 'S',
|
||
|
'e', 'E',
|
||
|
'l', 'L',
|
||
|
'o', 'O',
|
||
|
'z', 'Z',
|
||
|
'z', 'Z',
|
||
|
'n', 'N', 0 }; // 0 - terminating
|
||
|
|
||
|
|
||
|
int polish_letters_iso88592[] =
|
||
|
{ 0xb1, 0xa1,
|
||
|
0xe6, 0xc6,
|
||
|
0xb6, 0xa6,
|
||
|
0xea, 0xca,
|
||
|
0xb3, 0xa3,
|
||
|
0xf3, 0xd3,
|
||
|
0xbf, 0xaf,
|
||
|
0xbc, 0xac,
|
||
|
0xf1, 0xd1, 0 };
|
||
|
|
||
|
|
||
|
|
||
|
int ChangeLocalChar(unsigned char c)
|
||
|
{
|
||
|
// if( language == polish_iso88592 )
|
||
|
|
||
|
for(int i = 0 ; polish_letters_iso88592[i] ; ++i)
|
||
|
{
|
||
|
if( polish_letters_simple[i] == 0 )
|
||
|
{
|
||
|
log << log1 << "localization tables don't have the same size" << logend;
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
if( polish_letters_iso88592[i] == c )
|
||
|
return polish_letters_simple[i];
|
||
|
}
|
||
|
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
|
||
|
void HtmlSpecial(std::ostringstream & out, const std::string & in)
|
||
|
{
|
||
|
std::string::const_iterator i;
|
||
|
|
||
|
for(i = in.begin() ; i != in.end() ; ++i)
|
||
|
{
|
||
|
if( *i == '<' )
|
||
|
out << "<";
|
||
|
else
|
||
|
if( *i == '>' )
|
||
|
out << ">";
|
||
|
else
|
||
|
out << *i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
std::string HtmlSpecial(const std::string & in)
|
||
|
{
|
||
|
std::ostringstream out;
|
||
|
|
||
|
HtmlSpecial(out, in);
|
||
|
|
||
|
return out.str();
|
||
|
}
|
||
|
|
||
|
|
||
|
|