summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2012-07-24 11:45:50 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-07-24 18:07:42 +0200
commit01576a7d02cb205333e6a322d0cb5f77934981cb (patch)
tree203c7014170d302512a9492848a2a70b88251328
parent1e4ce7d760cfdc8eb2a5480d8037055c27d04325 (diff)
hwpfilter: improve text import and error handling
Signed-off-by: Miklos Vajna <vmiklos@suse.cz> (cherry picked from commit e0c3c823fd0c6a15c420992f2edb94bdc21996cd) Change-Id: Ia376daa336b0cf3b6f3b8f9964d59ca3fcceeeb6 Signed-off-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--hwpfilter/Library_hwp.mk1
-rw-r--r--hwpfilter/source/drawdef.h2
-rw-r--r--hwpfilter/source/drawing.h7
-rw-r--r--hwpfilter/source/formula.cxx25
-rw-r--r--hwpfilter/source/hbox.cxx56
-rw-r--r--hwpfilter/source/hbox.h50
-rw-r--r--hwpfilter/source/hcode.cxx196
-rw-r--r--hwpfilter/source/hcode.h10
-rw-r--r--hwpfilter/source/himgutil.cxx172
-rw-r--r--hwpfilter/source/himgutil.h69
-rw-r--r--hwpfilter/source/hpara.cxx10
-rw-r--r--hwpfilter/source/hstyle.cxx4
-rw-r--r--hwpfilter/source/htags.cxx6
-rw-r--r--hwpfilter/source/hwplib.h5
-rw-r--r--hwpfilter/source/hwpread.cxx41
-rw-r--r--hwpfilter/source/hwpreader.cxx323
-rw-r--r--hwpfilter/source/hwpreader.hxx4
-rw-r--r--hwpfilter/source/mapping.h28
18 files changed, 373 insertions, 636 deletions
diff --git a/hwpfilter/Library_hwp.mk b/hwpfilter/Library_hwp.mk
index ec189cd94bdf..66b7ffef8395 100644
--- a/hwpfilter/Library_hwp.mk
+++ b/hwpfilter/Library_hwp.mk
@@ -67,7 +67,6 @@ $(eval $(call gb_Library_add_exception_objects,hwp,\
hwpfilter/source/hcode \
hwpfilter/source/hfont \
hwpfilter/source/hgzip \
- hwpfilter/source/himgutil \
hwpfilter/source/hinfo \
hwpfilter/source/hiodev \
hwpfilter/source/hpara \
diff --git a/hwpfilter/source/drawdef.h b/hwpfilter/source/drawdef.h
index f83e5ef9b28f..5c0423c1f6e6 100644
--- a/hwpfilter/source/drawdef.h
+++ b/hwpfilter/source/drawdef.h
@@ -174,7 +174,7 @@ struct HWPDOProperty
ZZPoint offset1;
ZZPoint offset2;
- char szPatternFile[MAX_PATH + 1];
+ char szPatternFile[260 + 1];
char pictype;
};
diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h
index 2da39fb23ec0..3e630c2c4386 100644
--- a/hwpfilter/source/drawing.h
+++ b/hwpfilter/source/drawing.h
@@ -36,6 +36,8 @@
#include <osl/diagnose.h>
+#include <comphelper/newarray.hxx>
+
#include "hwplib.h"
#include "hwpfile.h"
#include "hiodev.h"
@@ -356,6 +358,7 @@ static HWPDrawingObject *LoadDrawingObject(void)
hdo->child = LoadDrawingObject();
if (hdo->child == NULL)
{
+ goto error;
}
}
if (prev == NULL)
@@ -552,7 +555,8 @@ int cmd, void *argp, int argv)
return OBJRET_FILE_ERROR;
if (hdo->u.freeform.npt)
{
- hdo->u.freeform.pt = new ZZPoint[hdo->u.freeform.npt];
+ hdo->u.freeform.pt =
+ ::comphelper::newArray_null<ZZPoint>(hdo->u.freeform.npt);
if (hdo->u.freeform.pt == NULL)
{
hdo->u.freeform.npt = 0;
@@ -639,6 +643,7 @@ int cmd, void *argp, int argv)
}
+
static int
HWPDOContainerFunc(int type, HWPDrawingObject * hdo,
int cmd, void *argp, int argv)
diff --git a/hwpfilter/source/formula.cxx b/hwpfilter/source/formula.cxx
index ec44f7d0ad74..c1903e27f83a 100644
--- a/hwpfilter/source/formula.cxx
+++ b/hwpfilter/source/formula.cxx
@@ -41,7 +41,6 @@ extern std::list<Node*> nodelist;
#include "hcode.h"
-static hchar entity[32];
#define ascii(x) OUString::createFromAscii(x)
#define rstartEl(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(0)
#define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(0)
@@ -50,7 +49,6 @@ static hchar entity[32];
#define reucstr(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->characters(OUString(x,y, RTL_TEXTENCODING_EUC_KR)); } while(0)
#define padd(x,y,z) pList->addAttribute(x,y,z)
#else
-static char entity[32];
static int indent = 0;
#define inds indent++; for(int i = 0 ; i < indent ; i++) fprintf(stderr," ")
#define inde for(int i = 0 ; i < indent ; i++) fprintf(stderr," "); indent--
@@ -231,11 +229,12 @@ void Formula::makeIdentifier(Node *res)
case ID_IDENTIFIER :
#ifdef DEBUG
inds;
- fprintf(stderr,"<math:mi>%s</math:mi>\n",getMathMLEntity(tmp->value, entity));
+ fprintf(stderr,"<math:mi>%s</math:mi>\n",
+ getMathMLEntity(tmp->value).c_str());
indo;
#else
rstartEl(ascii("math:mi"), rList);
- runistr(getMathMLEntity(tmp->value, entity));
+ runistr(getMathMLEntity(tmp->value).c_str());
rendEl(ascii("math:mi"));
#endif
break;
@@ -257,7 +256,7 @@ void Formula::makeIdentifier(Node *res)
inds; fprintf(stderr,"<math:mo>%s</math:mo>\n",tmp->value); indo;
#else
rstartEl(ascii("math:mo"), rList);
- runistr(getMathMLEntity(tmp->value,entity));
+ runistr(getMathMLEntity(tmp->value).c_str());
rendEl(ascii("math:mo"));
#endif
break;
@@ -413,11 +412,12 @@ void Formula::makeDecoration(Node *res)
#ifdef DEBUG
inds;
- fprintf(stderr,"<math:mo>%s</math:mo>\n", getMathMLEntity(tmp->value,entity));
+ fprintf(stderr,"<math:mo>%s</math:mo>\n",
+ getMathMLEntity(tmp->value).c_str());
indo;
#else
rstartEl(ascii("math:mo"), rList);
- runistr(getMathMLEntity(tmp->value,entity));
+ runistr(getMathMLEntity(tmp->value).c_str());
rendEl(ascii("math:mo"));
#endif
@@ -538,11 +538,14 @@ void Formula::makeFence(Node *res)
Node *tmp = res->child;
#ifdef DEBUG
inds;
- fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n",getMathMLEntity(tmp->value, entity),
- getMathMLEntity(tmp->next->next->value,entity));
+ fprintf(stderr,"<math:mfenced open=\"%s\" close=\"%s\">\n",
+ getMathMLEntity(tmp->value).c_str(),
+ getMathMLEntity(tmp->next->next->value).c_str());
#else
- padd(ascii("open"), ascii("CDATA"), OUString(getMathMLEntity(tmp->value,entity)) );
- padd(ascii("close"), ascii("CDATA"), OUString(getMathMLEntity(tmp->next->next->value,entity)) );
+ padd(ascii("open"), ascii("CDATA"),
+ OUString(getMathMLEntity(tmp->value).c_str()) );
+ padd(ascii("close"), ascii("CDATA"),
+ OUString(getMathMLEntity(tmp->next->next->value).c_str()) );
rstartEl(ascii("math:mfenced"), rList);
pList->clear();
#endif
diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx
index 1dafc7747d08..30c2d4827ad8 100644
--- a/hwpfilter/source/hbox.cxx
+++ b/hwpfilter/source/hbox.cxx
@@ -72,11 +72,11 @@ int HBox::WSize(void)
}
-int HBox::GetString(hchar * hstr, int )
+hchar_string HBox::GetString()
{
- *hstr++ = hh;
- *hstr = 0;
- return 1;
+ hchar_string ret;
+ ret.push_back(hh);
+ return ret;
}
@@ -152,10 +152,10 @@ DateCode::DateCode(void):HBox(CH_DATE_CODE)
#define _DATECODE_WEEK_DEFINES_
#include "datecode.h"
-int DateCode::GetString(hchar * hstr, int slen)
+hchar_string DateCode::GetString()
{
+ hchar_string ret;
const hchar *fmt;
- hchar *d;
int i, num;
const char *form;
char cbuf[256];
@@ -165,8 +165,7 @@ int DateCode::GetString(hchar * hstr, int slen)
format[DATE_SIZE - 1] = 0;
fmt = format[0] ? format : defaultform;
- d = hstr;
- for (; *fmt && ((int) (d - hstr) < DATE_SIZE) && slen > 1; fmt++)
+ for (; *fmt && ((int) ret.size() < DATE_SIZE); fmt++)
{
form = (add_zero) ? "%02d" : "%d";
@@ -230,8 +229,7 @@ int DateCode::GetString(hchar * hstr, int slen)
num = date[MIN];
break;
case '6':
- *d++ = kor_week[date[WEEK]];
- slen--;
+ ret.push_back(kor_week[date[WEEK]]);
break;
case '^':
memcpy(cbuf, eng_week + date[WEEK] * 3, 3);
@@ -242,11 +240,8 @@ int DateCode::GetString(hchar * hstr, int slen)
strcpy(cbuf, en_week[date[WEEK]]);
break;
case '7':
- if (slen > 3)
- {
- *d++ = 0xB5A1;
- *d++ = (is_pm) ? 0xD281 : 0xB8E5;
- }
+ ret.push_back(0xB5A1);
+ ret.push_back((is_pm) ? 0xD281 : 0xB8E5);
break;
case '&':
strcpy(cbuf, (is_pm) ? "p.m." : "a.m.");
@@ -279,28 +274,24 @@ int DateCode::GetString(hchar * hstr, int slen)
fmt++;
if (*fmt == '6')
{
- *d++ = china_week[date[WEEK]];
- slen--;
+ ret.push_back(china_week[date[WEEK]]);
break;
}
break;
default:
if (*fmt == '\\' && *++fmt == 0)
goto done;
- *d++ = *fmt;
- slen--;
+ ret.push_back(*fmt);
}
if (num != -1)
sprintf(cbuf, form, num);
- for (i = 0; 0 != cbuf[i] && slen > 1; i++)
+ for (i = 0; 0 != cbuf[i]; i++)
{
- *d++ = *(cbuf + i);
- slen--;
+ ret.push_back(*(cbuf + i));
}
}
done:
- *d = 0;
- return hstrlen(hstr);
+ return ret;
}
@@ -441,10 +432,9 @@ Footnote::~Footnote(void)
// 홀수쪽시작/감추기 (21)
// mail merge(22)
-int MailMerge::GetString(hchar * hstr, int )
+hchar_string MailMerge::GetString()
{
- *hstr = 0;
- return 0;
+ return hchar_string();
}
@@ -589,7 +579,7 @@ enum
number는 값이 그대로 들어가 있다. 즉, 1.2.1에는 1,2,1이 들어가 있다.
style 은 1부터 값이 들어가 있다. hbox.h에 정의된 데로..
*/
-hchar *Outline::GetUnicode(hchar * hstr, int)
+hchar_string Outline::GetUnicode() const
{
const hchar *p;
hchar buffer[255];
@@ -617,14 +607,14 @@ hchar *Outline::GetUnicode(hchar * hstr, int)
strcat(buf, cur_num_str);
}
str2hstr(buf, buffer);
- return hstr2ucsstr(buffer, hstr);
+ return hstr2ucsstr(buffer);
}
case OLSTY_NUMSIG1:
case OLSTY_NUMSIG2:
case OLSTY_NUMSIG3:
{
getOutlineNumStr(shape, level, number[level], buffer);
- return hstr2ucsstr(buffer, hstr);
+ return hstr2ucsstr(buffer);
}
case OLSTY_BULLET1:
case OLSTY_BULLET2:
@@ -635,7 +625,7 @@ hchar *Outline::GetUnicode(hchar * hstr, int)
p = GetOutlineStyleChars(shape);
buffer[0] = p[level];
buffer[1] = 0;
- return hstr2ucsstr(buffer, hstr);
+ return hstr2ucsstr(buffer);
}
case OLSTY_USER:
case OLSTY_BULUSER:
@@ -722,11 +712,11 @@ hchar *Outline::GetUnicode(hchar * hstr, int)
buffer[l++] = deco[i][1];
}
buffer[l] = 0;
- return hstr2ucsstr(buffer, hstr);
+ return hstr2ucsstr(buffer);
}
}
}
- return hstr2ucsstr(buffer, hstr);
+ return hstr2ucsstr(buffer);
}
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h
index 74c771334563..42ea4686ac79 100644
--- a/hwpfilter/source/hbox.h
+++ b/hwpfilter/source/hbox.h
@@ -69,12 +69,8 @@ struct HBox
* @returns True if reading from stream is successful.
*/
virtual int Read(HWPFile &hwpf);
-/**
- * @param hstr Buffer to save string
- * @param slen Size of buffer
- * @returns The string having each proper format by pointer
- */
- virtual int GetString(hchar *hstr, int slen = 255);
+
+ virtual hchar_string GetString();
private:
static int boxCount;
};
@@ -171,10 +167,8 @@ struct DateCode: public HBox
DateCode();
virtual int Read(HWPFile &hwpf);
-/**
- * @returns Length of date string
- */
- virtual int GetString(hchar *hstr, int slen = 255);
+
+ virtual hchar_string GetString();
};
/**
@@ -412,8 +406,8 @@ struct TxtBox: public FBox
struct Columns
{
int *data;
- int nCount;
- int nTotal;
+ size_t nCount;
+ size_t nTotal;
Columns(){
nCount = 0;
nTotal = INIT_SIZE;
@@ -423,8 +417,12 @@ struct Columns
void AddColumnsSize(){
int *tmp = data;
+ if (nTotal + ADD_AMOUNT < nTotal) // overflow
+ {
+ throw ::std::bad_alloc();
+ }
data = new int[nTotal + ADD_AMOUNT];
- for( int i = 0 ; i < nTotal ; i++ )
+ for (size_t i = 0 ; i < nTotal ; i++)
data[i] = tmp[i];
nTotal += ADD_AMOUNT;
delete[] tmp;
@@ -435,13 +433,13 @@ struct Columns
data[nCount++] = pos;
return;
}
- for( int i = 0 ; i < nCount; i++ ){
+ for (size_t i = 0 ; i < nCount; i++ ) {
if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
return; // Already exist;
if( pos < data[i] ){
if( nCount == nTotal )
AddColumnsSize();
- for( int j = nCount ; j > i ; j-- )
+ for (size_t j = nCount ; j > i ; j--)
data[j] = data[j-1];
data[i] = pos;
nCount++;
@@ -458,7 +456,7 @@ struct Columns
{
if( pos == 0 )
return 0;
- for( int i = 0 ; i < nCount; i++){
+ for (size_t i = 0 ; i < nCount; i++) {
if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
return i;
}
@@ -469,8 +467,8 @@ struct Columns
struct Rows
{
int *data;
- int nCount;
- int nTotal;
+ size_t nCount;
+ size_t nTotal;
Rows(){
nCount = 0;
nTotal = INIT_SIZE;
@@ -480,8 +478,12 @@ struct Rows
void AddRowsSize(){
int *tmp = data;
+ if (nTotal + ADD_AMOUNT < nTotal) // overflow
+ {
+ throw ::std::bad_alloc();
+ }
data = new int[nTotal + ADD_AMOUNT];
- for( int i = 0 ; i < nTotal ; i++ )
+ for (size_t i = 0 ; i < nTotal ; i++)
data[i] = tmp[i];
nTotal += ADD_AMOUNT;
delete[] tmp;
@@ -492,13 +494,13 @@ struct Rows
data[nCount++] = pos;
return;
}
- for( int i = 0 ; i < nCount; i++ ){
+ for (size_t i = 0 ; i < nCount; i++) {
if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
return; // Already exist;
if( pos < data[i] ){
if( nCount == nTotal )
AddRowsSize();
- for( int j = nCount ; j > i ; j-- )
+ for (size_t j = nCount ; j > i ; j--)
data[j] = data[j-1];
data[i] = pos;
nCount++;
@@ -515,7 +517,7 @@ struct Rows
{
if( pos == 0 )
return 0;
- for( int i = 0 ; i < nCount; i++){
+ for (size_t i = 0 ; i < nCount; i++) {
if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
return i;
}
@@ -869,7 +871,7 @@ struct MailMerge: public HBox
MailMerge();
virtual int Read(HWPFile &hwpf);
- virtual int GetString(hchar *, int slen = 255);
+ virtual hchar_string GetString();
};
// char compositon(23)
@@ -1007,7 +1009,7 @@ class Outline: public HBox
Outline();
virtual int Read(HWPFile &hwpf);
- hchar *GetUnicode(hchar *, int slen = 255);
+ hchar_string GetUnicode() const;
};
/* 묶음 빈칸(30) */
diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx
index 260d5648ba32..da0091231333 100644
--- a/hwpfilter/source/hcode.cxx
+++ b/hwpfilter/source/hcode.cxx
@@ -1191,31 +1191,28 @@ hchar ksc5601_han_to_ucs2 (hchar input)
return '?';
}
-hchar* hstr2ucsstr(hchar* hstr, hchar* ubuf)
+hchar_string hstr2ucsstr(hchar const* hstr)
{
- int i = 0, j;
- int res;
- hchar dest[3];
- hchar *tmp = ubuf;
- for( ; *hstr ; ){
- res = hcharconv(*hstr++, dest, UNICODE);
- for( j = 0 ; j < res ; j++)
- tmp[i++] = dest[j];
- }
-
- tmp[i]= '\0';
- return ubuf;
+ hchar_string ret;
+ hchar dest[3];
+ for( ; *hstr ; ){
+ int const res = hcharconv(*hstr++, dest, UNICODE);
+ for (int j = 0 ; j < res ; j++) {
+ ret.push_back(dest[j]);
+ }
+ }
+ return ret;
}
+
/**
* 한컴스트링을 완성형스트링으로 변환한다
*/
-int hstr2ksstr(hchar* hstr, char* buf)
+::std::string hstr2ksstr(hchar const* hstr)
{
-
- int i = 0, res, j;
+ ::std::string ret;
+ int res, j;
int c;
hchar dest[3];
- char *tmp = buf;
for( ; *hstr ; )
{
res = hcharconv(*hstr++, dest, KS);
@@ -1223,17 +1220,17 @@ int hstr2ksstr(hchar* hstr, char* buf)
c = dest[j];
if( c < 32 ) c = ' ';
else if( c < 256 )
- tmp[i++] = sal::static_int_cast<char>(c);
+ {
+ ret.push_back(sal::static_int_cast<char>(c));
+ }
else
{
- tmp[i++] = sal::static_int_cast<char>((c >> 8 ) & 0xff);
- tmp[i++] = sal::static_int_cast<char>(c & 0xff);
+ ret.push_back(sal::static_int_cast<char>((c >> 8 ) & 0xff));
+ ret.push_back(sal::static_int_cast<char>(c & 0xff));
}
}
}
- tmp[i]= '\0';
-
- return i;
+ return ret;
}
@@ -1241,25 +1238,22 @@ int hstr2ksstr(hchar* hstr, char* buf)
* 한글에서 영문외의 문자까지 포함할 수 있는 kchar타입의 문자열을
* 한글에서 사용하는 hchar타입의 문자열로 변환한다.
*/
-unsigned short *kstr2hstr( unsigned char *src, unsigned short *dest )
+hchar_string kstr2hstr(unsigned char const* src)
{
- int i=0, ii;
- unsigned short* tmp = dest;
-
- for(i=0,ii=0 ; src[i] != '\0' ; i++,ii++ )
+ hchar_string ret;
+ for (unsigned int i = 0; src[i] != '\0' ; i++)
{
if ( src[i] < 127 )
{
- tmp[ii] = src[i];
+ ret.push_back(src[i]);
}
else
{
- tmp[ii] = src[i] << 8 | src[i+1];
+ ret.push_back(src[i] << 8 | src[i+1]);
i++;
}
}
- tmp[ii] = '\0';
- return dest;
+ return ret;
}
@@ -1331,119 +1325,87 @@ char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar)
}
-char *urltounix(const char *src, char *dest )
+::std::string urltounix(const char *src)
{
+ ::std::string ret;
+ unsigned int i = 0;
if( src[0] == 'C' && src[1] == ':' && src[2] == '\\' ) // Home Dir
{
- unsigned int i, len;
- sprintf(dest,"file://%s/", getenv("HOME") );
- len = strlen( dest );
-
- for( i = 0 ; i + 3 < strlen(src) ; i++ )
- {
- if( src[i + 3] == '\\')
- dest[i + len] = '/';
- else
- dest[i + len] = src[ i +3];
- }
- dest[i + len] = '\0';
- return dest;
+ ret.append("file://");
+ ret.append(getenv("HOME"));
+ ret.push_back('/');
+ i = 3; // skip first 3
}
else if( src[0] == 'D' && src[1] == ':' && src[2] == '\\' ) // Root Dir
{
- unsigned int i, len;
- sprintf(dest,"file:///");
- len = strlen( dest );
- for( i = 0 ; i + 3 < strlen(src) ; i++ )
- {
- if( src[i + 3] == '\\')
- dest[i + len] = '/';
- else
- dest[i + len] = src[i+3];
- }
- dest[i + len] = '\0';
- return dest;
+ ret.append("file:///");
+ i = 3; // skip first 3
}
else if( !strncmp(src,"http",4) ) // Start from "http"
- {
- unsigned int i;
- for( i = 0 ; i < strlen(src) ; i++ )
- {
- if( src[i] == '\\')
- dest[i] = '/';
- else
- dest[i] = src[i];
- }
- dest[i] = '\0';
- return dest;
+ {
+ // nothing special here, just copy
}
else
{
- unsigned int i, len, srclen;
- srclen = strlen(src);
- char ext[4];
- strncpy(ext,src + srclen - 3,3);
- ext[3]=0;
+ unsigned int srclen = strlen(src);
+ if (3 < srclen)
+ {
+ char const*const ext = src + (srclen-3);
#ifdef _WIN32
- if( _strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
+ if (_strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
#else
- if( strcasecmp(ext,"HWP") && strcasecmp(ext,"HWT"))
+ if (strcasecmp(ext,"HWP") && strcasecmp(ext,"HWT"))
#endif
- sprintf(dest, "http://");
- len = strlen(dest);
- for( i = 0 ; i < strlen(src) ; i++ )
- {
- if( src[i] == '\\')
- dest[i+len] = '/';
- else
- dest[i+len] = src[i];
+ {
+ ret.append("http://");
+ }
+ }
+ }
+ for (; i < strlen(src); i++)
+ {
+ if (src[i] == '\\') {
+ ret.push_back('/');
+ } else {
+ ret.push_back(src[i]);
}
- dest[i+len] = '\0';
- return dest;
}
+ return ret;
}
#ifdef _WIN32
-char *urltowin(const char *src, char *dest )
+::std::string urltowin(const char *src)
{
+ std::string ret;
if( !_strnicmp(src, "http", 4))
{
- int i;
- for( i = 0 ; i < sal::static_int_cast<int>(strlen(src)) ; i++ )
- {
- if( src[i] == '\\')
- dest[i] = '/';
- else
- dest[i] = src[i];
- }
- dest[i] = '\0';
- return dest;
+ // nothing special here, just copy
}
else
{
- int i, len, srclen;
- srclen = strlen(src);
- char ext[4];
- strncpy(ext,src + srclen - 3,3);
- ext[3]=0;
- //printf("hcode.cxx : ext = %s\n",ext);
-
- if( !_strnicmp(ext,"HWP",3) || !_strnicmp(ext,"HWT",3)){
- strcpy(dest,src);
- return dest;
- }
- sprintf(dest, "http://");
- len = strlen(dest);
- for( i = 0 ; i < sal::static_int_cast<int>(strlen(src)) ; i++ )
+ unsigned int srclen = strlen(src);
+ if (3 < srclen)
{
- if( src[i] == '\\')
- dest[i+len] = '/';
+ char const*const ext = src + (srclen-3);
+ if (_strnicmp(ext,"HWP",3) && _strnicmp(ext,"HWT",3))
+ {
+ ret.append("http://");
+ }
else
- dest[i+len] = src[i];
+ {
+ ret.append(src); // no backslash conversion
+ return ret;
+ }
}
- dest[i+len] = '\0';
- return dest;
- }
+ }
+ for (unsigned int i = 0; i < strlen(src); i++)
+ {
+ if (src[i] == '\\') {
+ ret.push_back('/');
+ } else {
+ ret.push_back(src[i]);
+ }
+ }
+ return ret;
}
#endif
diff --git a/hwpfilter/source/hcode.h b/hwpfilter/source/hcode.h
index ef00cebcf010..6462dbbb04c3 100644
--- a/hwpfilter/source/hcode.h
+++ b/hwpfilter/source/hcode.h
@@ -44,27 +44,27 @@ DLLEXPORT int hcharconv(hchar ch, hchar *dest, int codeType) ;
DLLEXPORT int kssm_hangul_to_ucs2(hchar ch, hchar *dest) ;
DLLEXPORT hchar ksc5601_han_to_ucs2 (hchar);
DLLEXPORT hchar ksc5601_sym_to_ucs2 (hchar);
-DLLEXPORT hchar* hstr2ucsstr(hchar* hstr, hchar* ubuf);
+DLLEXPORT hchar_string hstr2ucsstr(hchar const* hstr);
/**
* 한컴스트링을 완성형스트링으로 변환한다.
*/
-DLLEXPORT int hstr2ksstr(hchar* hstr, char* buf);
+DLLEXPORT ::std::string hstr2ksstr(hchar const* hstr);
/**
* 한글을 포함할 수 있는 char형스트링을 한컴스트링으로 변환한다.
*/
-DLLEXPORT hchar *kstr2hstr( uchar *src, hchar *dest );
+DLLEXPORT hchar_string kstr2hstr(uchar const* src);
/**
* hwp의 경로를 unix형태로 바꾼다.
*/
-DLLEXPORT char *urltounix(const char *src, char *buf );
+DLLEXPORT ::std::string urltounix(const char *src);
/**
* hwp의 경로를 windows형태로 바꾼다.
*/
#ifdef _WIN32
-DLLEXPORT char *urltowin(const char *src, char *buf );
+DLLEXPORT ::std::string urltowin(const char *src);
#endif
/**
* Transfer interger to string following format
diff --git a/hwpfilter/source/himgutil.cxx b/hwpfilter/source/himgutil.cxx
deleted file mode 100644
index 3d94280f6135..000000000000
--- a/hwpfilter/source/himgutil.cxx
+++ /dev/null
@@ -1,172 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "precompile.h"
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "hwplib.h"
-#include "htags.h"
-#include "himgutil.h"
-
-
-static int ImageMagicType(const uchar * magicno)
-{
- int rv = RFT_UNKNOWN;
-
- if (strncmp((char *) magicno, "GIF87a", 6) == 0 ||
- strncmp((char *) magicno, "GIF89a", 6) == 0)
- rv = RFT_GIF;
- else if (strncmp((char *) magicno, "VIEW", 4) == 0 ||
- strncmp((char *) magicno, "WEIV", 4) == 0)
- rv = RFT_PM;
- else if (magicno[0] == 'P' && magicno[1] >= '1' && magicno[1] <= '6')
- rv = RFT_PBM;
-/* note: have to check XPM before XBM, as first 2 chars are the same */
- else if (strncmp((char *) magicno, "/* XPM */", 9) == 0)
- rv = RFT_XPM;
- else if (strncmp((char *) magicno, "#define", 7) == 0 ||
- (magicno[0] == '/' && magicno[1] == '*'))
- rv = RFT_XBM;
- else if (magicno[0] == 0x59 && (magicno[1] & 0x7f) == 0x26 &&
- magicno[2] == 0x6a && (magicno[3] & 0x7f) == 0x15)
- rv = RFT_SUNRAS;
- else if (magicno[0] == 'B' && magicno[1] == 'M')
- rv = RFT_BMP;
- else if (magicno[0] == 0x52 && magicno[1] == 0xcc)
- rv = RFT_UTAHRLE;
- else if ((magicno[0] == 0x01 && magicno[1] == 0xda) ||
- (magicno[0] == 0xda && magicno[1] == 0x01))
- rv = RFT_IRIS;
- else if (magicno[0] == 0x1f && magicno[1] == 0x9d)
- rv = RFT_COMPRESS;
- else if (magicno[0] == 0x0a && magicno[1] <= 5)
- rv = RFT_PCX;
- else if (strncmp((char *) magicno, "FORM", 4) == 0 &&
- strncmp((char *) magicno + 8, "ILBM", 4) == 0)
- rv = RFT_IFF;
- else if (magicno[0] == 0 && magicno[1] == 0 &&
- magicno[2] == 2 && magicno[3] == 0 &&
- magicno[4] == 0 && magicno[5] == 0 &&
- magicno[6] == 0 && magicno[7] == 0)
- rv = RFT_TARGA;
- else if (magicno[4] == 0x00 && magicno[5] == 0x00 &&
- magicno[6] == 0x00 && magicno[7] == 0x07)
- rv = RFT_XWD;
- else if (strncmp((char *) magicno, "SIMPLE ", 8) == 0 &&
- magicno[29] == 'T')
- rv = RFT_FITS;
- else if (magicno[0] == 0xff && magicno[1] == 0xd8 && magicno[2] == 0xff)
- rv = RFT_JFIF;
- else if ((magicno[0] == 'M' && magicno[1] == 'M') ||
- (magicno[0] == 'I' && magicno[1] == 'I'))
- rv = RFT_TIFF;
- else if (strncmp((char *) magicno, "%!", 2) == 0 ||
- strncmp((char *) magicno, "\004%!", 3) == 0)
- rv = RFT_PS;
- else if (strncmp((char *) magicno, "\xd7\xcd\xc6\x9a", 4) == 0 ||
- strncmp((char *) magicno, "\x01\x00\x09\x00\x00\x03", 6) == 0)
- rv = RFT_WMF;
-
- return rv;
-}
-
-const char *GetEmbImgname(const EmPicture * empic)
-{
- static char fname[256];
- char *ptr;
- const char *ext;
-
- if (tmpnam(fname) == NULL)
- return NULL;
- if (!empic || !empic->name[0] || (0 == (ptr = strrchr(fname, DIRSEP))))
- return NULL;
- switch (ImageMagicType((uchar *) empic->data))
- {
- case RFT_GIF:
- ext = "gif";
- break;
- case RFT_PM:
- ext = "pm";
- break;
- case RFT_PBM:
- ext = "pbm";
- break;
- case RFT_XBM:
- ext = "xbm";
- break;
- case RFT_SUNRAS:
- ext = "ras";
- break;
- case RFT_BMP:
- ext = "bmp";
- break;
- case RFT_UTAHRLE:
- ext = "rle";
- break;
- case RFT_PCX:
- ext = "pcx";
- break;
- case RFT_JFIF:
- ext = "jpg";
- break;
- case RFT_TIFF:
- ext = "tif";
- break;
- case RFT_PDSVICAR:
- ext = "pds";
- break;
- case RFT_PS:
- ext = "ps";
- break;
- case RFT_IFF:
- ext = "iff";
- break;
- case RFT_TARGA:
- ext = "tga";
- break;
- case RFT_XPM:
- ext = "xpm";
- break;
- case RFT_XWD:
- ext = "xwd";
- break;
- case RFT_WMF:
- ext = "wmf";
- break;
- default:
- ext = "666";
- break;
- };
- sprintf(ptr + 1, "mz_%s.%s", empic->name,ext);
- return fname;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/himgutil.h b/hwpfilter/source/himgutil.h
deleted file mode 100644
index 5b4c3842b33e..000000000000
--- a/hwpfilter/source/himgutil.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef _HIMGUTIL_H_
-#define _HIMGUTIL_H_
-
-/**
- * Graphics file format identifiers.
- */
-#define RFT_ERROR -1 /* couldn't open file, or whatever... */
-#define RFT_UNKNOWN 0
-#define RFT_GIF 1
-#define RFT_PM 2
-#define RFT_PBM 3
-#define RFT_XBM 4
-#define RFT_SUNRAS 5
-#define RFT_BMP 6
-#define RFT_UTAHRLE 7
-#define RFT_IRIS 8
-#define RFT_PCX 9
-#define RFT_JFIF 10
-#define RFT_TIFF 11
-#define RFT_PDSVICAR 12
-#define RFT_COMPRESS 13
-#define RFT_PS 14
-#define RFT_IFF 15
-#define RFT_TARGA 16
-#define RFT_XPM 17
-#define RFT_XWD 18
-#define RFT_FITS 19
-#define RFT_WMF 20
-
-// function declaration
-struct EmPicture;
-
-/**
- * Extract the name from given object
- * @param empic Object having name to extract
- * @returns Name of embeded picture
- */
-const char *GetEmbImgname(const EmPicture *empic);
-#endif /* _HIMGUTIL_H_ */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 9544f7ee0b8a..36268f63b633 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -30,6 +30,8 @@
#include <osl/diagnose.h>
+#include <comphelper/newarray.hxx>
+
#include "hwplib.h"
#include "hwpfile.h"
#include "hpara.h"
@@ -119,7 +121,8 @@ int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
pshape.pagebreak = etcflag;
}
- linfo = new LineInfo[nline];
+ linfo = ::comphelper::newArray_null<LineInfo>(nline);
+ if (!linfo) { return false; }
for (ii = 0; ii < nline; ii++)
{
linfo[ii].Read(hwpf, this);
@@ -146,7 +149,7 @@ int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
if (contain_cshape)
{
- cshapep = new CharShape[nch];
+ cshapep = ::comphelper::newArray_null<CharShape>(nch);
if (!cshapep)
{
perror("Memory Allocation: cshape\n");
@@ -170,7 +173,8 @@ int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
}
}
// read string
- hhstr = new HBox *[nch];
+ hhstr = ::comphelper::newArray_null<HBox *>(nch);
+ if (!hhstr) { return false; }
for (ii = 0; ii < nch; ii++)
hhstr[ii] = 0;
ii = 0;
diff --git a/hwpfilter/source/hstyle.cxx b/hwpfilter/source/hstyle.cxx
index 8cce811067a0..fef92998ccc3 100644
--- a/hwpfilter/source/hstyle.cxx
+++ b/hwpfilter/source/hstyle.cxx
@@ -28,6 +28,8 @@
#include "precompile.h"
+#include <comphelper/newarray.hxx>
+
#include "hwplib.h"
#include "hwpfile.h"
#include "hstyle.h"
@@ -132,7 +134,7 @@ bool HWPStyle::Read(HWPFile & hwpf)
ParaShape pshape;
hwpf.Read2b(&nstyles, 1);
- style = new StyleData[nstyles];
+ style = ::comphelper::newArray_null<StyleData>(nstyles);
if (!style)
return false;
diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx
index bd3ae34f0fa0..7358b3c2e233 100644
--- a/hwpfilter/source/htags.cxx
+++ b/hwpfilter/source/htags.cxx
@@ -33,7 +33,6 @@
#include "hwplib.h"
#include "hwpfile.h"
#include "htags.h"
-#include "himgutil.h"
bool HyperText::Read(HWPFile & hwpf)
{
@@ -68,11 +67,6 @@ EmPicture::EmPicture(size_t tsize)
#endif
EmPicture::~EmPicture(void)
{
-// clear temporary image file
- char *fname = (char *) GetEmbImgname(this);
-
- if (fname && access(fname, 0) == 0)
- unlink(fname);
if (data)
delete[]data;
};
diff --git a/hwpfilter/source/hwplib.h b/hwpfilter/source/hwplib.h
index f25f6631181f..9b9f37ec57a1 100644
--- a/hwpfilter/source/hwplib.h
+++ b/hwpfilter/source/hwplib.h
@@ -29,6 +29,9 @@
#ifndef _HWPLIB_H_
#define _HWPLIB_H_
#include "precompile.h"
+
+#include <string>
+
/* hwp96부터 hunit가 4byte가 되었다. */
/**
* size of hunit is 4 since hwp96 version
@@ -59,6 +62,8 @@ typedef unsigned int uint;
typedef unsigned long ulong;
#endif /* _UTYPE_ */
+typedef ::std::basic_string<hchar> hchar_string;
+
#ifndef _ZZRECT_
#define _ZZRECT_
/**
diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx
index db905f0c8986..ba6072d1fd7d 100644
--- a/hwpfilter/source/hwpread.cxx
+++ b/hwpfilter/source/hwpread.cxx
@@ -28,6 +28,8 @@
#include "precompile.h"
+#include <comphelper/newarray.hxx>
+
#include <list>
#include "hwpfile.h"
@@ -86,20 +88,30 @@ int FieldCode::Read(HWPFile & hwpf)
hwpf.Read4b(&len3, 1);
hwpf.Read4b(&binlen, 1);
- str1 = new hchar[len1];
- str2 = new hchar[len2];
- str3 = new hchar[len3];
+ ulong const len1_ = ((len1 > 1024) ? 1024 : len1) / sizeof(hchar);
+ ulong const len2_ = ((len2 > 1024) ? 1024 : len2) / sizeof(hchar);
+ ulong const len3_ = ((len3 > 1024) ? 1024 : len3) / sizeof(hchar);
+
+ str1 = new hchar[len1_ ? len1_ : 1];
+ str2 = new hchar[len2_ ? len2_ : 1];
+ str3 = new hchar[len3_ ? len3_ : 1];
bin = new char[binlen];
- hwpf.Read2b(str1, len1/2);
- hwpf.Read2b(str2, len2/2);
- hwpf.Read2b(str3, len3/2);
+ hwpf.Read2b(str1, len1_);
+ hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar)));
+ str1[len1_ ? (len1_ - 1) : 0] = 0;
+ hwpf.Read2b(str2, len2_);
+ hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar)));
+ str2[len2_ ? (len2_ - 1) : 0] = 0;
+ hwpf.Read2b(str3, len3_);
+ hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar)));
+ str3[len3_ ? (len3_ - 1) : 0] = 0;
hwpf.ReadBlock(bin, binlen);
if( type[0] == 3 && type[1] == 2 ){ /* 만든날짜로서 포맷을 생성해야 한다. */
DateCode *pDate = new DateCode;
- for( int i = 0 ;i < (int)(len3/2) ; i++ ){
+ for (int i = 0 ; i < static_cast<int>(len3_); i++) {
if(str3[i] == 0 ) break;
if( i >= DATE_SIZE ) break;
pDate->format[i] = str3[i];
@@ -286,7 +298,10 @@ int TxtBox::Read(HWPFile & hwpf)
return hwpf.SetState(HWP_InvalidFileFormat);
}
- cell = new Cell[ncell];
+ cell = ::comphelper::newArray_null<Cell>(ncell);
+ if (!cell) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
for (ii = 0; ii < ncell; ii++)
{
cell[ii].Read(hwpf);
@@ -294,7 +309,10 @@ int TxtBox::Read(HWPFile & hwpf)
}
if (ncell == 1)
style.cell = &cell[0];
- plists = new std::list < HWPPara* >[ncell];
+ plists = ::comphelper::newArray_null< std::list< HWPPara* > >(ncell);
+ if (!plists) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
for (ii = 0; ii < ncell; ii++)
hwpf.ReadParaList(plists[ii]);
// caption
@@ -309,7 +327,10 @@ int TxtBox::Read(HWPFile & hwpf)
tbl->rows.insert(cell[ii].y);
tbl->rows.insert(cell[ii].y + cell[ii].h);
}
- TCell* *pArr = new TCell*[ncell];
+ TCell* *pArr = ::comphelper::newArray_null<TCell *>(ncell);
+ if (!pArr) {
+ return hwpf.SetState(HWP_InvalidFileFormat);
+ }
for( ii = 0 ; ii < ncell; ii++)
{
TCell *tcell = new TCell;
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index ff7a112e5bff..412a96662451 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -33,6 +33,9 @@
#include "hwpreader.hxx"
#include <math.h>
+
+#include <comphelper/newarray.hxx>
+
#include "formula.h"
#include "cspline.h"
@@ -47,7 +50,7 @@ extern int getRepFamilyName(const char* , char *, double &ratio);
#endif
// To be shorten source code by realking
-#define hconv(x,y) OUString(hstr2ucsstr(x,y))
+#define hconv(x) OUString(hstr2ucsstr(x).c_str())
#define ascii(x) OUString::createFromAscii(x)
#define rstartEl(x,y) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->startElement(x,y); } while(0)
#define rendEl(x) do { if (m_rxDocumentHandler.is()) m_rxDocumentHandler->endElement(x); } while(0)
@@ -80,8 +83,6 @@ extern int getRepFamilyName(const char* , char *, double &ratio);
rendEl(ascii("text:span")); \
tstart = false
-static hchar gstr[1024];
-static hchar sbuf[256];
static hchar *field = 0L;
static char buf[1024];
@@ -256,21 +257,21 @@ void HwpReader::makeMeta()
if (hwpinfo->summary.title[0])
{
rstartEl(ascii("dc:title"), rList);
- rchars((hconv(hwpinfo->summary.title, gstr)));
+ rchars((hconv(hwpinfo->summary.title)));
rendEl(ascii("dc:title"));
}
if (hwpinfo->summary.subject[0])
{
rstartEl(ascii("dc:subject"), rList);
- rchars((hconv(hwpinfo->summary.subject, gstr)));
+ rchars((hconv(hwpinfo->summary.subject)));
rendEl(ascii("dc:subject"));
}
if (hwpinfo->summary.author[0])
{
rstartEl(ascii("meta:initial-creator"), rList);
- rchars((hconv(hwpinfo->summary.author, gstr)));
+ rchars((hconv(hwpinfo->summary.author)));
rendEl(ascii("meta:initial-creator"));
}
@@ -344,31 +345,31 @@ void HwpReader::makeMeta()
if (hwpinfo->summary.keyword[0][0])
{
rstartEl(ascii("meta:keyword"), rList);
- rchars((hconv(hwpinfo->summary.keyword[0], gstr)));
+ rchars((hconv(hwpinfo->summary.keyword[0])));
rendEl(ascii("meta:keyword"));
}
if (hwpinfo->summary.keyword[1][0])
{
rstartEl(ascii("meta:keyword"), rList);
- rchars((hconv(hwpinfo->summary.keyword[1], gstr)));
+ rchars((hconv(hwpinfo->summary.keyword[1])));
rendEl(ascii("meta:keyword"));
}
if (hwpinfo->summary.etc[0][0])
{
rstartEl(ascii("meta:keyword"), rList);
- rchars((hconv(hwpinfo->summary.etc[0], gstr)));
+ rchars((hconv(hwpinfo->summary.etc[0])));
rendEl(ascii("meta:keyword"));
}
if (hwpinfo->summary.etc[1][0])
{
rstartEl(ascii("meta:keyword"), rList);
- rchars((hconv(hwpinfo->summary.etc[1], gstr)));
+ rchars((hconv(hwpinfo->summary.etc[1])));
rendEl(ascii("meta:keyword"));
}
if (hwpinfo->summary.etc[2][0])
{
rstartEl(ascii("meta:keyword"), rList);
- rchars((hconv(hwpinfo->summary.etc[2], gstr)));
+ rchars((hconv(hwpinfo->summary.etc[2])));
rendEl(ascii("meta:keyword"));
}
rendEl(ascii("meta:keywords"));
@@ -514,7 +515,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
if( !prop->pictype )
{
padd( ascii("xlink:href"), sXML_CDATA,
- hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile, buf), sbuf), gstr));
+ hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile).c_str()).c_str()));
}
else
{
@@ -523,7 +524,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
emp = hwpfile.GetEmPictureByName(prop->szPatternFile);
if( emp )
{
- char filename[128];
+ char filename[128+17+9];
char dirname[128];
int fd;
#ifdef _WIN32
@@ -557,7 +558,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo )
else
{
padd( ascii("xlink:href"), sXML_CDATA,
- hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile, buf), sbuf), gstr));
+ hconv(kstr2hstr( (uchar *)urltounix(prop->szPatternFile).c_str()).c_str()));
}
}
@@ -738,7 +739,7 @@ void HwpReader::makeStyles()
for (int ii = 0; ii < hwpstyle->Num(); ii++)
{
unsigned char *stylename = (unsigned char *) hwpstyle->GetName(ii);
- padd(ascii("style:name"), sXML_CDATA, (hconv(kstr2hstr(stylename, sbuf), gstr)));
+ padd(ascii("style:name"), sXML_CDATA, (hconv(kstr2hstr(stylename).c_str())));
padd(ascii("style:family"), sXML_CDATA, ascii("paragraph"));
padd(ascii("style:parent-style-name"), sXML_CDATA, ascii("Standard"));
@@ -1336,10 +1337,10 @@ void HwpReader::parseCharShape(CharShape * cshape)
padd(ascii("style:font-size-asian"), sXML_CDATA,
ascii(Int2Str(cshape->size / 25, "%dpt", buf)));
- char tmp[128];
- hstr2ksstr(kstr2hstr((unsigned char *) hwpfont->GetFontName(0, cshape->font[0]), sbuf), tmp);
+ ::std::string const tmp = hstr2ksstr(kstr2hstr(
+ (unsigned char *) hwpfont->GetFontName(0, cshape->font[0])).c_str());
double fRatio = 1.0;
- int size = getRepFamilyName(tmp,buf, fRatio);
+ int size = getRepFamilyName(tmp.c_str(), buf, fRatio);
padd(ascii("fo:font-family"), sXML_CDATA,
OUString(buf, size, RTL_TEXTENCODING_EUC_KR));
@@ -1720,10 +1721,10 @@ void HwpReader::makePageStyle()
if( hwpinfo->back_info.type == 1 ){
#ifdef _WIN32
padd(ascii("xlink:href"), sXML_CDATA,
- hconv(kstr2hstr((uchar *) urltowin(hwpinfo->back_info.filename, buf), sbuf), gstr));
+ hconv(kstr2hstr((uchar*) urltowin(hwpinfo->back_info.filename).c_str()).c_str()));
#else
padd(ascii("xlink:href"), sXML_CDATA,
- hconv(kstr2hstr( (uchar *)urltounix(hwpinfo->back_info.filename, buf), sbuf), gstr));
+ hconv(kstr2hstr( (uchar *)urltounix(hwpinfo->back_info.filename).c_str()).c_str()));
#endif
padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
padd(ascii("xlink:actuate"), sXML_CDATA, ascii("onLoad"));
@@ -1884,10 +1885,9 @@ void HwpReader::makeTableStyle(Table *tbl)
rendEl(ascii("style:style"));
// --------------- column ---------------- //
- int i ;
- for( i = 0 ; i < tbl->columns.nCount -1 ; i++ )
+ for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
{
- sprintf(buf,"Table%d.%c",hbox->style.boxnum, 'A'+i);
+ sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
padd(ascii("style:family"), sXML_CDATA,ascii("table-column"));
rstartEl(ascii("style:style"), rList);
@@ -1901,9 +1901,9 @@ void HwpReader::makeTableStyle(Table *tbl)
}
// --------------- row ---------------- //
- for( i = 0 ; i < tbl->rows.nCount -1 ; i++ )
+ for (size_t i = 0 ; i < tbl->rows.nCount -1 ; i++)
{
- sprintf(buf,"Table%d.row%d",hbox->style.boxnum, i + 1);
+ sprintf(buf,"Table%d.row%ld",hbox->style.boxnum, i + 1);
padd(ascii("style:name"), sXML_CDATA, ascii( buf ));
padd(ascii("style:family"), sXML_CDATA,ascii("table-row"));
rstartEl(ascii("style:style"), rList);
@@ -1917,7 +1917,7 @@ void HwpReader::makeTableStyle(Table *tbl)
}
// --------------- cell --------------------- //
- for( i = 0 ; i < (int)tbl->cells.size(); i++ )
+ for (int i = 0 ; i < static_cast<int>(tbl->cells.size()); i++)
{
std::list<TCell*>::iterator it = tbl->cells.begin();
@@ -2701,13 +2701,10 @@ char *HwpReader::getPStyleName(int index, char *_buf)
}
-void HwpReader::makeChars(hchar *str, int size)
+void HwpReader::makeChars(hchar_string & rStr)
{
- if (size)
- {
- str[size] = '\0';
- rchars(OUString(str));
- }
+ rchars(OUString(rStr.c_str()));
+ rStr.clear();
}
@@ -2716,8 +2713,9 @@ void HwpReader::makeChars(hchar *str, int size)
*/
void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
{
+ hchar_string str;
int n;
- int l = 0, res;
+ int res;
hchar dest[3];
unsigned char firstspace = 0;
if( !bParaStart)
@@ -2751,15 +2749,13 @@ void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
{
if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
{
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
rstartEl(ascii("text:s"), rList);
rendEl(ascii("text:s"));
}
else if (para->hhstr[n]->hh == CH_END_PARA)
{
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
rendEl(ascii("text:span"));
rendEl(ascii("text:p"));
break;
@@ -2772,7 +2768,9 @@ void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
firstspace = 1;
res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
for( int j = 0 ; j < res; j++ )
- gstr[l++] = dest[j];
+ {
+ str.push_back(dest[j]);
+ }
}
}
}
@@ -2783,8 +2781,9 @@ void HwpReader::make_text_p0(HWPPara * para, sal_Bool bParaStart)
*/
void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
{
+ hchar_string str;
int n;
- int l = 0, res;
+ int res;
hchar dest[3];
int curr = para->cshape.index;
unsigned char firstspace = 0;
@@ -2821,8 +2820,7 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
{
if (para->GetCharShape(n)->index != curr)
{
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
rendEl(ascii("text:span"));
curr = para->GetCharShape(n)->index;
padd(ascii("text:style-name"), sXML_CDATA,
@@ -2832,15 +2830,13 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
}
if (para->hhstr[n]->hh == CH_SPACE && !firstspace)
{
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
rstartEl(ascii("text:s"), rList);
rendEl(ascii("text:s"));
}
else if (para->hhstr[n]->hh == CH_END_PARA)
{
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
rendEl(ascii("text:span"));
rendEl(ascii("text:p"));
break;
@@ -2855,7 +2851,9 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
firstspace = 1;
res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
for( int j = 0 ; j < res; j++ )
- gstr[l++] = dest[j];
+ {
+ str.push_back(dest[j]);
+ }
}
}
}
@@ -2866,9 +2864,9 @@ void HwpReader::make_text_p1(HWPPara * para,sal_Bool bParaStart)
*/
void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
+ hchar_string str;
int n, res;
hchar dest[3];
- size_t l = 0;
unsigned char firstspace = 0;
bool pstart = bParaStart;
bool tstart = false;
@@ -2898,12 +2896,11 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
if( para->hhstr[n]->hh == CH_END_PARA )
{
- if( l > 0 )
+ if (str.size() > 0)
{
if( !pstart ){ STARTP;}
if( !tstart ){ STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
if( tstart ){ ENDT;}
if( !pstart ){ STARTP;}
@@ -2914,8 +2911,7 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
rstartEl(ascii("text:s"), rList);
pList->clear();
rendEl(ascii("text:s"));
@@ -2927,9 +2923,8 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
+ makeChars(str);
ENDT;
- l = 0;
}
if( para->hhstr[n]->hh == CH_SPACE )
firstspace = 0;
@@ -2937,7 +2932,9 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
firstspace = 1;
res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
for( int j = 0 ; j < res; j++ )
- gstr[l++] = dest[j];
+ {
+ str.push_back(dest[j]);
+ }
}
else if (para->hhstr[n]->hh == CH_FIELD)
{
@@ -2946,15 +2943,14 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
firstspace = 1;
if( hbox->type[0] == 4 && hbox->type[1] == 0 )
{
field = hbox->str3;
}
else{
- makeFieldCode(hbox);
+ makeFieldCode(str, hbox);
}
infield = true;
}
@@ -2963,12 +2959,11 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
firstspace = 1;
if( hbox->type[0] == 4 && hbox->type[1] == 0 )
{
- gstr[l] = 0;
- makeFieldCode(hbox);
+ makeFieldCode(str, hbox);
field = 0L;
}
infield = false;
- l = 0;
+ str.clear();
}
}
else
@@ -2978,8 +2973,7 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
case CH_BOOKMARK:
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeBookmark((Bookmark *) para->hhstr[n]);
break;
case CH_DATE_FORM: // 7
@@ -2987,17 +2981,15 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
case CH_DATE_CODE: // 8
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeDateCode((DateCode *) para->hhstr[n]);
break;
case CH_TAB: // 9
if( !pstart ) {STARTP;}
- if( l > 0 )
+ if (str.size() > 0)
{
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
makeTab((Tab *) para->hhstr[n]);
break;
@@ -3010,17 +3002,15 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
else
{
if( !pstart ) {STARTP;}
- if( l > 0 )
+ if (str.size() > 0)
{
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
if( tstart ) {ENDT;}
}
@@ -3045,17 +3035,15 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
{
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
else
{
if( !pstart ) {STARTP;}
- if( l > 0 )
+ if (str.size() > 0)
{
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
if( tstart ) {ENDT;}
}
@@ -3065,12 +3053,11 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
case CH_LINE: // 14
{
Line *hbox = (Line *) para->hhstr[n];
- if( l > 0 )
+ if (str.size() > 0)
{
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
}
if( tstart ) {ENDT;}
if( pstart ) {ENDP;}
@@ -3081,22 +3068,19 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
case CH_HIDDEN: // 15
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeHidden((Hidden *) para->hhstr[n]);
break;
case CH_FOOTNOTE: // 17
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeFootnote((Footnote *) para->hhstr[n]);
break;
case CH_AUTO_NUM: // 18
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeAutoNum((AutoNum *) para->hhstr[n]);
break;
case CH_NEW_NUM: // 19 -skip
@@ -3106,8 +3090,7 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
case CH_MAIL_MERGE: // 22
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeMailMerge((MailMerge *) para->hhstr[n]);
break;
case CH_COMPOSE: /* 23 - 湲옄寃뱀묠 */
@@ -3117,27 +3100,24 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
case CH_TOC_MARK: /* 25 븘옒쓽 3媛쒕뒗 옉뾽빐빞 븳떎. */
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeTocMark((TocMark *) para->hhstr[n]);
break;
case CH_INDEX_MARK: // 26
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeIndexMark((IndexMark *) para->hhstr[n]);
break;
case CH_OUTLINE: // 28
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
- makeChars(gstr, l);
- l = 0;
+ makeChars(str);
makeOutline((Outline *) para->hhstr[n]);
break;
case CH_FIXED_SPACE:
case CH_KEEP_SPACE:
- gstr[l++] = 0x0020;
+ str.push_back(0x0020);
break;
}
}
@@ -3145,108 +3125,108 @@ void HwpReader::make_text_p3(HWPPara * para,sal_Bool bParaStart)
}
-void HwpReader::makeFieldCode(FieldCode *hbox)
+void HwpReader::makeFieldCode(hchar_string & rStr, FieldCode *hbox)
{
/* 늻由꾪 */
if( hbox->type[0] == 4 && hbox->type[1] == 0 )
{
padd(ascii("text:placeholder-type"), sXML_CDATA, ascii("text"));
if( field )
- padd(ascii("text:description"), sXML_CDATA, hconv(field, sbuf));
+ padd(ascii("text:description"), sXML_CDATA, hconv(field));
rstartEl( ascii("text:placeholder"), rList);
pList->clear();
- rchars( OUString(gstr));
+ rchars( OUString(rStr.c_str()));
rendEl( ascii("text:placeholder") );
}
/* 臾몄꽌슂빟 */
else if( hbox->type[0] == 3 && hbox->type[1] == 0 )
{
- if( hconv( hbox->str3, gstr ) == "title" )
+ if (hconv(hbox->str3) == "title")
{
rstartEl( ascii("text:title"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:title") );
}
- else if( hconv( hbox->str3, gstr ) == "subject" )
+ else if (hconv(hbox->str3) == "subject")
{
rstartEl( ascii("text:subject"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:subject") );
}
- else if( hconv( hbox->str3, gstr ) == "author" )
+ else if (hconv(hbox->str3) == "author")
{
rstartEl( ascii("text:author-name"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:author-name") );
}
- else if( hconv( hbox->str3, gstr ) == "keywords" )
+ else if (hconv(hbox->str3) == "keywords")
{
rstartEl( ascii("text:keywords"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:keywords") );
}
}
/* 媛쒖씤젙蹂 */
else if( hbox->type[0] == 3 && hbox->type[1] == 1 )
{
- if( hconv( hbox->str3, gstr ) == "User" )
+ if (hconv(hbox->str3) == "User")
{
rstartEl( ascii("text:sender-lastname"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-lastname") );
}
- else if( hconv( hbox->str3, gstr ) == "Company" )
+ else if (hconv(hbox->str3) == "Company")
{
rstartEl( ascii("text:sender-company"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-company") );
}
- else if( hconv( hbox->str3, gstr ) == "Position" )
+ else if (hconv(hbox->str3) == "Position")
{
rstartEl( ascii("text:sender-title"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-title") );
}
- else if( hconv( hbox->str3, gstr ) == "Division" )
+ else if (hconv(hbox->str3) == "Division")
{
rstartEl( ascii("text:sender-position"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-position") );
}
- else if( hconv( hbox->str3, gstr ) == "Fax" )
+ else if (hconv(hbox->str3) == "Fax")
{
rstartEl( ascii("text:sender-fax"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-fax") );
}
- else if( hconv( hbox->str3, gstr ) == "Pager" )
+ else if (hconv(hbox->str3) == "Pager")
{
rstartEl( ascii("text:phone-private"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:phone-private") );
}
- else if( hconv( hbox->str3, gstr ) == "E-mail" )
+ else if (hconv(hbox->str3) == "E-mail")
{
rstartEl( ascii("text:sender-email"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-email") );
}
- else if( hconv( hbox->str3, gstr ) == "Zipcode(office)" )
+ else if (hconv(hbox->str3) == "Zipcode(office)")
{
rstartEl( ascii("text:sender-postal-code"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-postal-code") );
}
- else if( hconv( hbox->str3, gstr ) == "Phone(office)" )
+ else if (hconv(hbox->str3) == "Phone(office)")
{
rstartEl( ascii("text:sender-phone-work"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-phone-work") );
}
- else if( hconv( hbox->str3, gstr ) == "Address(office)" )
+ else if (hconv(hbox->str3) == "Address(office)")
{
rstartEl( ascii("text:sender-street"), rList );
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:sender-street") );
}
@@ -3258,7 +3238,7 @@ void HwpReader::makeFieldCode(FieldCode *hbox)
ascii(Int2Str(hbox->m_pDate->key, "N%d", buf)));
rstartEl( ascii("text:creation-date"), rList );
pList->clear();
- rchars( hconv(hbox->str2, gstr) );
+ rchars( hconv(hbox->str2) );
rendEl( ascii("text:creation-date") );
}
}
@@ -3272,21 +3252,21 @@ void HwpReader::makeBookmark(Bookmark * hbox)
{
if (hbox->type == 0)
{
- padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id, gstr)));
+ padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
rstartEl(ascii("text:bookmark"), rList);
pList->clear();
rendEl(ascii("text:bookmark"));
}
else if (hbox->type == 1) /* 釉붾줉 遺곷쭏겕씪 寃쎌슦 떆옉怨 걹씠 엳떎 */
{
- padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id, gstr)));
+ padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
rstartEl(ascii("text:bookmark-start"), rList);
pList->clear();
rendEl(ascii("text:bookmark-start"));
}
else if (hbox->type == 2)
{
- padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id, gstr)));
+ padd(ascii("text:name"), sXML_CDATA, (hconv(hbox->id)));
rstartEl(ascii("text:bookmark-end"), rList);
pList->clear();
rendEl(ascii("text:bookmark-end"));
@@ -3430,10 +3410,11 @@ void HwpReader::makeDateFormat(DateCode * hbox)
case '~': // Chinese Locale
break;
default:
+ hchar sbuf[2];
sbuf[0] = *fmt;
sbuf[1] = 0;
rstartEl(ascii("number:text"), rList);
- rchars((hconv(sbuf, gstr)));
+ rchars((hconv(sbuf)));
rendEl(ascii("number:text"));
break;
}
@@ -3449,8 +3430,8 @@ void HwpReader::makeDateCode(DateCode * hbox)
ascii(Int2Str(hbox->key, "N%d", buf)));
rstartEl( ascii("text:date"), rList );
pList->clear();
- hbox->GetString(sbuf, 255);
- rchars((hconv(sbuf, gstr)));
+ hchar_string const boxstr = hbox->GetString();
+ rchars((hconv(boxstr.c_str())));
rendEl( ascii("text:date") );
}
@@ -3473,10 +3454,9 @@ void HwpReader::makeTable(TxtBox * hbox)
Table *tbl = hbox->m_pTable;
// ----------- column ---------------- //
- int i ;
- for( i = 0 ; i < tbl->columns.nCount -1 ; i++ )
+ for (size_t i = 0 ; i < tbl->columns.nCount -1 ; i++)
{
- sprintf(buf,"Table%d.%c",hbox->style.boxnum, 'A'+i);
+ sprintf(buf,"Table%d.%c",hbox->style.boxnum, static_cast<char>('A'+i));
padd(ascii("table:style-name"), sXML_CDATA, ascii( buf ));
rstartEl(ascii("table:table-column"), rList);
pList->clear();
@@ -3485,7 +3465,7 @@ void HwpReader::makeTable(TxtBox * hbox)
// ----------- cell ---------------- //
int j = -1, k = -1;
- for( i = 0 ; i < (int)tbl->cells.size(); i++ )
+ for (int i = 0 ; i < static_cast<int>(tbl->cells.size()); i++)
{
std::list<TCell*>::iterator it = tbl->cells.begin();
@@ -3706,7 +3686,7 @@ void HwpReader::makeFormula(TxtBox * hbox)
{
if (!cshape)
cshape = pPar->GetCharShape(n);
- if (l >= sizeof(mybuf)-1)
+ if (l >= sizeof(mybuf)-7)
break;
res = hcharconv(pPar->hhstr[n]->hh, dest, UNICODE);
for( int j = 0 ; j < res; j++ ){
@@ -3722,7 +3702,7 @@ void HwpReader::makeFormula(TxtBox * hbox)
}
}
}
- if (l >= sizeof(mybuf)-1)
+ if (l >= sizeof(mybuf)-7)
break;
mybuf[l++] = '\n';
pPar = pPar->Next();
@@ -3749,32 +3729,35 @@ void HwpReader::makeHyperText(TxtBox * hbox)
if( !hypert ) return;
if( strlen((char *)hypert->filename) > 0 ){
- char tmp[256];
- char tmp2[256];
- int nSize = hstr2ksstr(hypert->bookmark, tmp);
+ ::std::string const tmp = hstr2ksstr(hypert->bookmark);
+ ::std::string const tmp2 = hstr2ksstr(kstr2hstr(
#ifdef _WIN32
- int nSize2 = hstr2ksstr(kstr2hstr((uchar *) urltowin((char *)hypert->filename, buf), sbuf), tmp2);
+ (uchar *) urltowin((char *)hypert->filename).c_str()).c_str());
#else
- int nSize2 = hstr2ksstr(kstr2hstr( (uchar *)urltounix((char *)hypert->filename, buf), sbuf), tmp2);
+ (uchar *) urltounix((char *)hypert->filename).c_str()).c_str());
#endif
padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
- if( strlen(tmp) > 0 && strcmp( tmp, "[HTML]") ){
- sprintf( buf, "%s#%s",tmp2, tmp);
- padd(ascii("xlink:href"), sXML_CDATA, OUString(buf, nSize2 + nSize+1, RTL_TEXTENCODING_EUC_KR));
+ if (tmp.size() > 0 && strcmp(tmp.c_str(), "[HTML]")) {
+ ::std::string tmp3(tmp2);
+ tmp3.push_back('#');
+ tmp3.append(tmp);
+ padd(ascii("xlink:href"), sXML_CDATA,
+ OUString(tmp3.c_str(), tmp3.size()+1, RTL_TEXTENCODING_EUC_KR));
}
else{
- sprintf( buf, "%s",tmp2);
- padd(ascii("xlink:href"), sXML_CDATA, OUString(buf, nSize2, RTL_TEXTENCODING_EUC_KR));
+ padd(ascii("xlink:href"), sXML_CDATA,
+ OUString(tmp2.c_str(), tmp2.size()+1, RTL_TEXTENCODING_EUC_KR));
}
}
else
{
- char tmp[256];
padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
- int nSize = hstr2ksstr(hypert->bookmark, tmp);
- sprintf( buf, "#%s", tmp);
- padd(ascii("xlink:href"), sXML_CDATA, OUString(buf, nSize+1, RTL_TEXTENCODING_EUC_KR));
+ ::std::string tmp;
+ tmp.push_back('#');
+ tmp.append(hstr2ksstr(hypert->bookmark));
+ padd(ascii("xlink:href"), sXML_CDATA,
+ OUString(tmp.c_str(), tmp.size()+1, RTL_TEXTENCODING_EUC_KR));
}
rstartEl(ascii("draw:a"), rList);
pList->clear();
@@ -3847,16 +3830,16 @@ void HwpReader::makePicture(Picture * hbox)
padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
#ifdef _WIN32
if( hbox->follow[4] != 0 )
- padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 4, sbuf), gstr)));
+ padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 4).c_str())));
else
- padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 5, sbuf), gstr)));
+ padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr(hbox->follow + 5).c_str())));
#else
if( hbox->follow[4] != 0 )
padd(ascii("xlink:href"), sXML_CDATA,
- (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 4), buf), sbuf), gstr)));
+ (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 4)).c_str()).c_str())));
else
padd(ascii("xlink:href"), sXML_CDATA,
- (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 5), buf), sbuf), gstr)));
+ (hconv(kstr2hstr((uchar *)urltounix((char *)(hbox->follow + 5)).c_str()).c_str())));
#endif
rstartEl(ascii("draw:a"), rList);
pList->clear();
@@ -3908,10 +3891,10 @@ void HwpReader::makePicture(Picture * hbox)
if ( hbox->pictype == PICTYPE_FILE ){
#ifdef _WIN32
sprintf(buf, "file:///%s", hbox->picinfo.picun.path );
- padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr((uchar *) buf, sbuf), gstr)));
+ padd(ascii("xlink:href"), sXML_CDATA, (hconv(kstr2hstr((uchar *) buf).c_str())));
#else
padd(ascii("xlink:href"), sXML_CDATA,
- (hconv(kstr2hstr((uchar *) urltounix( hbox->picinfo.picun.path, buf), sbuf), gstr)));
+ (hconv(kstr2hstr((uchar *) urltounix(hbox->picinfo.picun.path).c_str()).c_str())));
#endif
padd(ascii("xlink:type"), sXML_CDATA, ascii("simple"));
padd(ascii("xlink:show"), sXML_CDATA, ascii("embed"));
@@ -4376,7 +4359,10 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox)
OUString oustr;
- if (drawobj->u.freeform.npt > 2){
+ if ((drawobj->u.freeform.npt > 2) &&
+ (static_cast<size_t>(drawobj->u.freeform.npt) <
+ (::std::numeric_limits<int>::max() / sizeof(double))))
+ {
int n, i;
n = drawobj->u.freeform.npt;
@@ -4615,7 +4601,8 @@ void HwpReader::makeLine(Line * )
*/
void HwpReader::makeHidden(Hidden * hbox)
{
- int l = 0, res;
+ hchar_string str;
+ int res;
hchar dest[3];
padd(ascii("text:condition"), sXML_CDATA, ascii(""));
@@ -4631,11 +4618,13 @@ void HwpReader::makeHidden(Hidden * hbox)
{
res = hcharconv(para->hhstr[n]->hh, dest, UNICODE);
for( int j = 0 ; j < res ; j++ )
- gstr[l++] = dest[j];
+ {
+ str.push_back(dest[j]);
+ }
}
para = para->Next();
}
- makeChars(gstr, l);
+ makeChars(str);
rendEl(ascii("text:hidden-text"));
}
@@ -4780,8 +4769,8 @@ void HwpReader::makeShowPageNum()
*/
void HwpReader::makeMailMerge(MailMerge * hbox)
{
- hbox->GetString(sbuf, 255);
- rchars((hconv(sbuf, gstr)));
+ hchar_string const boxstr = hbox->GetString();
+ rchars((hconv(boxstr.c_str())));
}
@@ -4806,7 +4795,7 @@ void HwpReader::makeIndexMark(IndexMark * ) /*hbox */
void HwpReader::makeOutline(Outline * hbox)
{
if( hbox->kind == 1 )
- rchars(OUString(hbox->GetUnicode(sbuf, 255)));
+ rchars(OUString(hbox->GetUnicode().c_str()));
}
diff --git a/hwpfilter/source/hwpreader.hxx b/hwpfilter/source/hwpreader.hxx
index 2c315bc42c83..c0b3d5c80661 100644
--- a/hwpfilter/source/hwpreader.hxx
+++ b/hwpfilter/source/hwpreader.hxx
@@ -139,10 +139,10 @@ private:
void make_text_p3(HWPPara *para, sal_Bool bParaStart = sal_False);
/* -------- rDocument->characters(x) --------- */
- void makeChars(hchar *, int);
+ void makeChars(hchar_string & rStr);
/* -------- Special Char Parsing --------- */
- void makeFieldCode(FieldCode *hbox); //6
+ void makeFieldCode(hchar_string & rStr, FieldCode *hbox); //6
void makeBookmark(Bookmark *hbox); //6
void makeDateFormat(DateCode *hbox); //7
void makeDateCode(DateCode *hbox); //8
diff --git a/hwpfilter/source/mapping.h b/hwpfilter/source/mapping.h
index 89e29c96feac..e56472b17565 100644
--- a/hwpfilter/source/mapping.h
+++ b/hwpfilter/source/mapping.h
@@ -33,7 +33,8 @@
#include <stdio.h>
#include <sal/macros.h>
-typedef unsigned short hchar;
+#include <hwplib.h>
+
struct FormulaEntry{
const char *tex;
@@ -369,30 +370,31 @@ const struct FormulaEntry FormulaMapTab[] = {
};
#ifndef DEBUG
-hchar *getMathMLEntity(const char *tex, hchar *buf)
+hchar_string getMathMLEntity(const char *tex)
{
- static int tabSize = SAL_N_ELEMENTS( FormulaMapTab );
- int i, len;
+ static size_t tabSize = sizeof(FormulaMapTab) / sizeof(FormulaMapTab[0]);
- for( i = 0 ; i < tabSize ; i++ ){
+ hchar_string buf;
+ for (size_t i = 0 ; i < tabSize ; i++) {
if( !strcmp(tex, FormulaMapTab[i].tex ) ) {
- buf[0] = FormulaMapTab[i].ucs;
- buf[1] = '\0';
+ buf.push_back(FormulaMapTab[i].ucs);
return buf;
}
}
- len = strlen(tex);
- for( i = 0 ; i < len ; i++ )
- buf[i] = tex[i];
- buf[len] = 0;
+ size_t const len = strlen(tex);
+ for (size_t i = 0 ; i < len ; i++)
+ {
+ buf.push_back(tex[i]);
+ }
return buf;
}
#else
-char *getMathMLEntity(const char *tex, char *buf)
+::std::string getMathMLEntity(const char *tex)
{
- strcpy(buf,tex);
+ ::std::string buf;
+ buf.append(tex);
return buf;
}
#endif