2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QPDF_Name.hh>
|
|
|
|
|
2008-05-04 16:02:53 +00:00
|
|
|
#include <string.h>
|
2008-11-23 19:11:24 +00:00
|
|
|
#include <stdio.h>
|
2013-01-25 13:59:55 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2008-05-04 16:02:53 +00:00
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
QPDF_Name::QPDF_Name(std::string const& name) :
|
|
|
|
name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_Name::~QPDF_Name()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDF_Name::normalizeName(std::string const& name)
|
|
|
|
{
|
2013-10-05 09:52:42 +00:00
|
|
|
if (name.empty())
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string result;
|
2013-10-05 23:42:39 +00:00
|
|
|
result += name.at(0);
|
2008-04-29 12:55:25 +00:00
|
|
|
for (unsigned int i = 1; i < name.length(); ++i)
|
|
|
|
{
|
2013-10-05 23:42:39 +00:00
|
|
|
char ch = name.at(i);
|
2009-02-21 02:54:31 +00:00
|
|
|
// Don't use locale/ctype here; follow PDF spec guidelines.
|
2008-04-29 12:55:25 +00:00
|
|
|
if (strchr("#()<>[]{}/%", ch) || (ch < 33) || (ch > 126))
|
|
|
|
{
|
2013-01-25 13:59:55 +00:00
|
|
|
result += "#" + QUtil::hex_encode(std::string(&ch, 1));
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDF_Name::unparse()
|
|
|
|
{
|
|
|
|
return normalizeName(this->name);
|
|
|
|
}
|
|
|
|
|
2013-01-22 14:57:07 +00:00
|
|
|
QPDFObject::object_type_e
|
|
|
|
QPDF_Name::getTypeCode() const
|
|
|
|
{
|
|
|
|
return QPDFObject::ot_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const*
|
|
|
|
QPDF_Name::getTypeName() const
|
|
|
|
{
|
|
|
|
return "name";
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string
|
|
|
|
QPDF_Name::getName() const
|
|
|
|
{
|
|
|
|
return this->name;
|
|
|
|
}
|