Fixes #719. Pass the string representation of the parameter name, and post process before output. Adds strrep() service to support.

This commit is contained in:
Jim Derry 2021-07-30 16:40:48 -04:00
parent 80550d6779
commit 68a3d81d02
9 changed files with 86 additions and 7 deletions

View file

@ -2022,7 +2022,7 @@ static Bool TIDY_CALL reportCallback(TidyMessage tmessage)
TidyFormatParameterType messageType; TidyFormatParameterType messageType;
ctmbstr messageFormat; ctmbstr messageFormat;
printf("FILTER: %s, %s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage )); printf("FILTER: %s\n%s\n%s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage ), tidyGetMessageOutputDefault( tmessage ));
/* loop through the arguments, if any, and print their details */ /* loop through the arguments, if any, and print their details */
pos = tidyGetMessageArguments( tmessage ); pos = tidyGetMessageArguments( tmessage );

View file

@ -2125,6 +2125,16 @@ TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedStringN(uint messageType, /**< The me
*/ */
TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedString( uint messageType ); TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedString( uint messageType );
/** Provides a string given `messageType` in the default localization for
** `quantity`. Some strings have one or more plural forms, and this function
** will ensure that the correct singular or plural form is returned for the
** specified quantity.
** @result Returns the desired string.
*/
TIDY_EXPORT ctmbstr TIDY_CALL tidyDefaultStringN(uint messageType, /**< The message type. */
uint quantity /**< The quantity. */
);
/** Provides a string given `messageType` in the default localization (which /** Provides a string given `messageType` in the default localization (which
** is `en`). ** is `en`).
** @param messageType The message type. ** @param messageType The message type.

View file

@ -476,6 +476,16 @@ TY_PRIVATE void TY_(tidySetLanguageSetByUser)( void )
} }
/**
* Provides a string given `messageType` in the default
* localization (which is `en`), for the given quantity.
*/
TY_PRIVATE ctmbstr TY_(tidyDefaultStringN)( uint messageType, uint quantity )
{
return tidyLocalizedStringImpl( messageType, &language_en, quantity);
}
/** /**
* Provides a string given `messageType` in the default * Provides a string given `messageType` in the default
* localization (which is `en`), for single plural form. * localization (which is `en`), for single plural form.

View file

@ -153,6 +153,12 @@ TY_PRIVATE ctmbstr TY_(tidyLocalizedString)( uint messageType );
/** @{ */ /** @{ */
/**
* Provides a string given `messageType` in the default
* localization (which is `en`), for the given quantity.
*/
TY_PRIVATE ctmbstr TY_(tidyDefaultStringN)( uint messageType, uint quantity );
/** /**
* Provides a string given `messageType` in the default * Provides a string given `messageType` in the default
* localization (which is `en`). * localization (which is `en`).

View file

@ -50,9 +50,9 @@ static char* TagToString(Node* tag, char* buf, size_t count)
else if (tag->type == DocTypeTag) else if (tag->type == DocTypeTag)
TY_(tmbsnprintf)(buf, count, "<!DOCTYPE>"); TY_(tmbsnprintf)(buf, count, "<!DOCTYPE>");
else if (tag->type == TextNode) else if (tag->type == TextNode)
TY_(tmbsnprintf)(buf, count, "%s", tidyLocalizedString(STRING_PLAIN_TEXT)); TY_(tmbsnprintf)(buf, count, "%s", "STRING_PLAIN_TEXT");
else if (tag->type == XmlDecl) else if (tag->type == XmlDecl)
TY_(tmbsnprintf)(buf, count, "%s", tidyLocalizedString(STRING_XML_DECLARATION)); TY_(tmbsnprintf)(buf, count, "%s", "STRING_XML_DECLARATION");
else if (tag->element) else if (tag->element)
TY_(tmbsnprintf)(buf, count, "%s", tag->element); TY_(tmbsnprintf)(buf, count, "%s", tag->element);
} }
@ -1070,7 +1070,7 @@ static struct _dialogueDispatchTable {
/* This message formatter for dialogue messages should be capable of formatting /* This message formatter for dialogue messages should be capable of formatting
** every message, because they're not all the complex and there aren't that ** every message, because they're not all that complex and there aren't that
** many. ** many.
*/ */
static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportLevel level, va_list args ) static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportLevel level, va_list args )
@ -1087,8 +1087,8 @@ static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportL
case STRING_ERROR_COUNT: case STRING_ERROR_COUNT:
case STRING_NOT_ALL_SHOWN: case STRING_NOT_ALL_SHOWN:
return TY_(tidyMessageCreate)( doc, code, level, return TY_(tidyMessageCreate)( doc, code, level,
doc->warnings, tidyLocalizedStringN( STRING_ERROR_COUNT_WARNING, doc->warnings ), doc->warnings, "STRING_ERROR_COUNT_WARNING",
doc->errors, tidyLocalizedStringN( STRING_ERROR_COUNT_ERROR, doc->errors ) ); doc->errors, "STRING_ERROR_COUNT_ERROR" );
case FOOTNOTE_TRIM_EMPTY_ELEMENT: case FOOTNOTE_TRIM_EMPTY_ELEMENT:
case STRING_HELLO_ACCESS: case STRING_HELLO_ACCESS:

View file

@ -40,7 +40,6 @@ struct printfArg {
}; };
/** Returns a pointer to an allocated array of `printfArg` given a format /** Returns a pointer to an allocated array of `printfArg` given a format
** string and a va_list, or NULL if not successful or no parameters were ** string and a va_list, or NULL if not successful or no parameters were
** given. Parameter `rv` will return with the count of zero or more ** given. Parameter `rv` will return with the count of zero or more
@ -130,6 +129,22 @@ static TidyMessageImpl *tidyMessageCreateInitV( TidyDocImpl *doc,
TY_(tmbvsnprintf)(result->message, sizeMessageBuf, result->messageFormat, args_copy); TY_(tmbvsnprintf)(result->message, sizeMessageBuf, result->messageFormat, args_copy);
va_end(args_copy); va_end(args_copy);
/* Some things already hit us localized, and some things need to be
localized here. Look for these codewords and replace them here.
*/
TY_(strrep)(result->messageDefault, "STRING_PLAIN_TEXT", tidyDefaultString(STRING_PLAIN_TEXT));
TY_(strrep)(result->message, "STRING_PLAIN_TEXT", tidyLocalizedString(STRING_PLAIN_TEXT));
TY_(strrep)(result->messageDefault, "STRING_XML_DECLARATION", tidyDefaultString(STRING_XML_DECLARATION));
TY_(strrep)(result->message, "STRING_XML_DECLARATION", tidyLocalizedString(STRING_XML_DECLARATION));
TY_(strrep)(result->messageDefault, "STRING_ERROR_COUNT_WARNING", tidyDefaultStringN(STRING_ERROR_COUNT_WARNING, doc->warnings));
TY_(strrep)(result->message, "STRING_ERROR_COUNT_WARNING", tidyLocalizedStringN(STRING_ERROR_COUNT_WARNING, doc->warnings));
TY_(strrep)(result->messageDefault, "STRING_ERROR_COUNT_ERROR", tidyDefaultStringN(STRING_ERROR_COUNT_ERROR, doc->errors));
TY_(strrep)(result->message, "STRING_ERROR_COUNT_ERROR", tidyLocalizedStringN(STRING_ERROR_COUNT_ERROR, doc->errors));
result->messagePosDefault = TidyDocAlloc(doc, sizeMessageBuf); result->messagePosDefault = TidyDocAlloc(doc, sizeMessageBuf);
result->messagePos = TidyDocAlloc(doc, sizeMessageBuf); result->messagePos = TidyDocAlloc(doc, sizeMessageBuf);

View file

@ -2643,6 +2643,11 @@ ctmbstr TIDY_CALL tidyLocalizedString( uint messageType )
return TY_(tidyLocalizedString)( messageType ); return TY_(tidyLocalizedString)( messageType );
} }
ctmbstr TIDY_CALL tidyDefaultStringN( uint messageType, uint quantity )
{
return TY_(tidyDefaultStringN)( messageType, quantity);
}
ctmbstr TIDY_CALL tidyDefaultString( uint messageType ) ctmbstr TIDY_CALL tidyDefaultString( uint messageType )
{ {
return TY_(tidyDefaultString)( messageType ); return TY_(tidyDefaultString)( messageType );

View file

@ -247,6 +247,36 @@ int TY_(tmbsnprintf)(tmbstr buffer, size_t count, ctmbstr format, ...)
return retval; return retval;
} }
void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep)
{
char *p = strstr(buffer, str);
do
{
if(p)
{
char buf[1024];
memset(buf,'\0',strlen(buf));
if(buffer == p)
{
strcpy(buf,rep);
strcat(buf,p+strlen(str));
}
else
{
strncpy(buf,buffer,strlen(buffer) - strlen(p));
strcat(buf,rep);
strcat(buf,p+strlen(str));
}
memset(buffer,'\0',strlen(buffer));
strcpy(buffer,buf);
}
} while(p && (p = strstr(buffer, str)));
}
/* /*
* local variables: * local variables:
* mode: c * mode: c

View file

@ -79,6 +79,9 @@ __attribute__((format(printf, 3, 4)))
#endif #endif
; ;
TY_PRIVATE void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif