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>
|
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)
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
char num[4];
|
|
|
|
result += name[0];
|
|
|
|
for (unsigned int i = 1; i < name.length(); ++i)
|
|
|
|
{
|
|
|
|
char ch = name[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))
|
|
|
|
{
|
|
|
|
sprintf(num, "#%02x", (unsigned char) ch);
|
|
|
|
result += num;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDF_Name::unparse()
|
|
|
|
{
|
|
|
|
return normalizeName(this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDF_Name::getName() const
|
|
|
|
{
|
|
|
|
return this->name;
|
|
|
|
}
|