From 5d8d2dfd9783779235013f51430b56252ebcc66d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 14 Feb 2011 15:27:45 +0000 Subject: [PATCH] 2011-02-14 16:27 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbtip/utils.c * contrib/hbtip/hbtip.hbx + Applied update from Lorenzo: - removed text/plain logic in magic search since this breaks css and js mimes - removed magic check for pkzip (today many formats like ooxml and odf are zips) - added extension mime for css, js, ods, xlsx, zip - added TIP_JSONSPECIALCHARS() * Formatting, cleaned error calls, variables names and scopes (also in TIP_HTMLSPECIALCHARS()) * TIP_JSONSPECIALCHARS(), TIP_HTMLSPECIALCHARS(): Changed to not RTE when empty string is passed. Empty string will return empty string. --- harbour/ChangeLog | 12 +++ harbour/contrib/hbtip/hbtip.hbx | 1 + harbour/contrib/hbtip/utils.c | 172 ++++++++++++++++++++++---------- 3 files changed, 130 insertions(+), 55 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 904d80d1b2..da26976671 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2011-02-14 16:27 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbtip/utils.c + * contrib/hbtip/hbtip.hbx + + Applied update from Lorenzo: + - removed text/plain logic in magic search since this breaks css and js mimes + - removed magic check for pkzip (today many formats like ooxml and odf are zips) + - added extension mime for css, js, ods, xlsx, zip + - added TIP_JSONSPECIALCHARS() + * Formatting, cleaned error calls, variables names and scopes (also in TIP_HTMLSPECIALCHARS()) + * TIP_JSONSPECIALCHARS(), TIP_HTMLSPECIALCHARS(): Changed to not RTE + when empty string is passed. Empty string will return empty string. + 2011-02-14 14:39 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/hbwin.hbx * contrib/hbwin/win_regc.c diff --git a/harbour/contrib/hbtip/hbtip.hbx b/harbour/contrib/hbtip/hbtip.hbx index dd863220f4..92ff348c9d 100644 --- a/harbour/contrib/hbtip/hbtip.hbx +++ b/harbour/contrib/hbtip/hbtip.hbx @@ -64,6 +64,7 @@ DYNAMIC TIP_GETENCODER DYNAMIC TIP_GETNAMEEMAIL DYNAMIC TIP_GETRAWEMAIL DYNAMIC TIP_HTMLSPECIALCHARS +DYNAMIC TIP_JSONSPECIALCHARS DYNAMIC TIP_MIMETYPE DYNAMIC TIP_SSL DYNAMIC TIP_TIMESTAMP diff --git a/harbour/contrib/hbtip/utils.c b/harbour/contrib/hbtip/utils.c index 72af2eafea..e1e3c62b9a 100644 --- a/harbour/contrib/hbtip/utils.c +++ b/harbour/contrib/hbtip/utils.c @@ -128,7 +128,7 @@ typedef struct tag_mime #define MIME_FLAG_TRIMTABS 0x0002 #define MIME_FLAG_CASEINSENS 0x0004 #define MIME_FLAG_CONTINUE 0x0008 -#define MIME_TABLE_SIZE 72 +#define MIME_TABLE_SIZE 71 static MIME_ENTRY s_mimeTable[ MIME_TABLE_SIZE ] = { @@ -196,7 +196,7 @@ static MIME_ENTRY s_mimeTable[ MIME_TABLE_SIZE ] = /* 46*/ { 0, "\x1F\x8B", "application/x-gzip", 0, 0, 0 }, /* PKzip */ - /* 47*/ { 0, "PK\x03\x04", "application/x-zip", 0, 0, 0 }, + /* 47 { 0, "PK\x03\x04", "application/x-zip", 0, 0, 0 }, 2010-12-15 support of xlsx/ods */ /* xml */ /* 48*/ { 0, "= ' ' ) { - cRet[ nPosRet ] = cElem; - nPosRet++; + cRet[ nPosRet++ ] = cElem; } nPos++; @@ -664,7 +645,7 @@ HB_FUNC( TIP_HTMLSPECIALCHARS ) hb_retc_null(); } else - hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, 1, hb_paramError( 1 ) ); + hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } #if defined( HB_LEGACY_LEVEL3 ) @@ -682,3 +663,84 @@ HB_FUNC( TIP_CRLF ) { hb_retc_const( "\r\n" ); } + +HB_FUNC( TIP_JSONSPECIALCHARS ) +{ + if( HB_ISCHAR( 1 ) ) + { + HB_ISIZ nLen = hb_parclen( 1 ); + + if( nLen ) + { + const char * pszData = hb_parc( 1 ); + char * cRet; + HB_ISIZ nPos = 0; + HB_ISIZ nPosRet = 0; + HB_BYTE cElem; + + while( nLen && HB_ISSPACE( pszData[ nLen - 1 ] ) ) + nLen--; + + /* Giving maximum final length possible */ + cRet = ( char * ) hb_xgrab( nLen * 6 + 1 ); + + while( nPos < nLen ) + { + cElem = ( HB_BYTE ) pszData[ nPos ]; + + if( cElem == '"' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = '"'; + } + else if( cElem == '\\' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = '\\'; + } + else if( cElem == '/' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = '/'; + } + else if( cElem == '\b' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = 'b'; + } + else if( cElem == '\f' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = 'f'; + } + else if( cElem == '\r' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = 'r'; + } + else if( cElem == '\n' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = 'n'; + } + else if( cElem == '\t' ) + { + cRet[ nPosRet++ ] = '\\'; + cRet[ nPosRet++ ] = 't'; + } + else if( cElem >= ' ' ) + { + cRet[ nPosRet++ ] = cElem; + } + + nPos++; + } + + hb_retclen_buffer( cRet, nPosRet ); + } + else + hb_retc_null(); + } + else + hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +}