Skip to content

Commit 68a3d81

Browse files
committed
Fixes #719. Pass the string representation of the parameter name, and post process before output. Adds strrep() service to support.
1 parent 80550d6 commit 68a3d81

File tree

9 files changed

+86
-7
lines changed

9 files changed

+86
-7
lines changed

console/tidy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ static Bool TIDY_CALL reportCallback(TidyMessage tmessage)
20222022
TidyFormatParameterType messageType;
20232023
ctmbstr messageFormat;
20242024

2025-
printf("FILTER: %s, %s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage ));
2025+
printf("FILTER: %s\n%s\n%s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage ), tidyGetMessageOutputDefault( tmessage ));
20262026

20272027
/* loop through the arguments, if any, and print their details */
20282028
pos = tidyGetMessageArguments( tmessage );

include/tidy.h

+10
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,16 @@ TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedStringN(uint messageType, /**< The me
21252125
*/
21262126
TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedString( uint messageType );
21272127

2128+
/** Provides a string given `messageType` in the default localization for
2129+
** `quantity`. Some strings have one or more plural forms, and this function
2130+
** will ensure that the correct singular or plural form is returned for the
2131+
** specified quantity.
2132+
** @result Returns the desired string.
2133+
*/
2134+
TIDY_EXPORT ctmbstr TIDY_CALL tidyDefaultStringN(uint messageType, /**< The message type. */
2135+
uint quantity /**< The quantity. */
2136+
);
2137+
21282138
/** Provides a string given `messageType` in the default localization (which
21292139
** is `en`).
21302140
** @param messageType The message type.

src/language.c

+10
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,16 @@ TY_PRIVATE void TY_(tidySetLanguageSetByUser)( void )
476476
}
477477

478478

479+
/**
480+
* Provides a string given `messageType` in the default
481+
* localization (which is `en`), for the given quantity.
482+
*/
483+
TY_PRIVATE ctmbstr TY_(tidyDefaultStringN)( uint messageType, uint quantity )
484+
{
485+
return tidyLocalizedStringImpl( messageType, &language_en, quantity);
486+
}
487+
488+
479489
/**
480490
* Provides a string given `messageType` in the default
481491
* localization (which is `en`), for single plural form.

src/language.h

+6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ TY_PRIVATE ctmbstr TY_(tidyLocalizedString)( uint messageType );
153153
/** @{ */
154154

155155

156+
/**
157+
* Provides a string given `messageType` in the default
158+
* localization (which is `en`), for the given quantity.
159+
*/
160+
TY_PRIVATE ctmbstr TY_(tidyDefaultStringN)( uint messageType, uint quantity );
161+
156162
/**
157163
* Provides a string given `messageType` in the default
158164
* localization (which is `en`).

src/message.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ static char* TagToString(Node* tag, char* buf, size_t count)
5050
else if (tag->type == DocTypeTag)
5151
TY_(tmbsnprintf)(buf, count, "<!DOCTYPE>");
5252
else if (tag->type == TextNode)
53-
TY_(tmbsnprintf)(buf, count, "%s", tidyLocalizedString(STRING_PLAIN_TEXT));
53+
TY_(tmbsnprintf)(buf, count, "%s", "STRING_PLAIN_TEXT");
5454
else if (tag->type == XmlDecl)
55-
TY_(tmbsnprintf)(buf, count, "%s", tidyLocalizedString(STRING_XML_DECLARATION));
55+
TY_(tmbsnprintf)(buf, count, "%s", "STRING_XML_DECLARATION");
5656
else if (tag->element)
5757
TY_(tmbsnprintf)(buf, count, "%s", tag->element);
5858
}
@@ -1070,7 +1070,7 @@ static struct _dialogueDispatchTable {
10701070

10711071

10721072
/* This message formatter for dialogue messages should be capable of formatting
1073-
** every message, because they're not all the complex and there aren't that
1073+
** every message, because they're not all that complex and there aren't that
10741074
** many.
10751075
*/
10761076
static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportLevel level, va_list args )
@@ -1087,8 +1087,8 @@ static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportL
10871087
case STRING_ERROR_COUNT:
10881088
case STRING_NOT_ALL_SHOWN:
10891089
return TY_(tidyMessageCreate)( doc, code, level,
1090-
doc->warnings, tidyLocalizedStringN( STRING_ERROR_COUNT_WARNING, doc->warnings ),
1091-
doc->errors, tidyLocalizedStringN( STRING_ERROR_COUNT_ERROR, doc->errors ) );
1090+
doc->warnings, "STRING_ERROR_COUNT_WARNING",
1091+
doc->errors, "STRING_ERROR_COUNT_ERROR" );
10921092

10931093
case FOOTNOTE_TRIM_EMPTY_ELEMENT:
10941094
case STRING_HELLO_ACCESS:

src/messageobj.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct printfArg {
4040
};
4141

4242

43-
4443
/** Returns a pointer to an allocated array of `printfArg` given a format
4544
** string and a va_list, or NULL if not successful or no parameters were
4645
** given. Parameter `rv` will return with the count of zero or more
@@ -130,6 +129,22 @@ static TidyMessageImpl *tidyMessageCreateInitV( TidyDocImpl *doc,
130129
TY_(tmbvsnprintf)(result->message, sizeMessageBuf, result->messageFormat, args_copy);
131130
va_end(args_copy);
132131

132+
/* Some things already hit us localized, and some things need to be
133+
localized here. Look for these codewords and replace them here.
134+
*/
135+
TY_(strrep)(result->messageDefault, "STRING_PLAIN_TEXT", tidyDefaultString(STRING_PLAIN_TEXT));
136+
TY_(strrep)(result->message, "STRING_PLAIN_TEXT", tidyLocalizedString(STRING_PLAIN_TEXT));
137+
138+
TY_(strrep)(result->messageDefault, "STRING_XML_DECLARATION", tidyDefaultString(STRING_XML_DECLARATION));
139+
TY_(strrep)(result->message, "STRING_XML_DECLARATION", tidyLocalizedString(STRING_XML_DECLARATION));
140+
141+
TY_(strrep)(result->messageDefault, "STRING_ERROR_COUNT_WARNING", tidyDefaultStringN(STRING_ERROR_COUNT_WARNING, doc->warnings));
142+
TY_(strrep)(result->message, "STRING_ERROR_COUNT_WARNING", tidyLocalizedStringN(STRING_ERROR_COUNT_WARNING, doc->warnings));
143+
144+
TY_(strrep)(result->messageDefault, "STRING_ERROR_COUNT_ERROR", tidyDefaultStringN(STRING_ERROR_COUNT_ERROR, doc->errors));
145+
TY_(strrep)(result->message, "STRING_ERROR_COUNT_ERROR", tidyLocalizedStringN(STRING_ERROR_COUNT_ERROR, doc->errors));
146+
147+
133148
result->messagePosDefault = TidyDocAlloc(doc, sizeMessageBuf);
134149
result->messagePos = TidyDocAlloc(doc, sizeMessageBuf);
135150

src/tidylib.c

+5
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,11 @@ ctmbstr TIDY_CALL tidyLocalizedString( uint messageType )
26432643
return TY_(tidyLocalizedString)( messageType );
26442644
}
26452645

2646+
ctmbstr TIDY_CALL tidyDefaultStringN( uint messageType, uint quantity )
2647+
{
2648+
return TY_(tidyDefaultStringN)( messageType, quantity);
2649+
}
2650+
26462651
ctmbstr TIDY_CALL tidyDefaultString( uint messageType )
26472652
{
26482653
return TY_(tidyDefaultString)( messageType );

src/tmbstr.c

+30
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,36 @@ int TY_(tmbsnprintf)(tmbstr buffer, size_t count, ctmbstr format, ...)
247247
return retval;
248248
}
249249

250+
void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep)
251+
{
252+
char *p = strstr(buffer, str);
253+
do
254+
{
255+
if(p)
256+
{
257+
char buf[1024];
258+
memset(buf,'\0',strlen(buf));
259+
260+
if(buffer == p)
261+
{
262+
strcpy(buf,rep);
263+
strcat(buf,p+strlen(str));
264+
}
265+
else
266+
{
267+
strncpy(buf,buffer,strlen(buffer) - strlen(p));
268+
strcat(buf,rep);
269+
strcat(buf,p+strlen(str));
270+
}
271+
272+
memset(buffer,'\0',strlen(buffer));
273+
strcpy(buffer,buf);
274+
}
275+
276+
} while(p && (p = strstr(buffer, str)));
277+
}
278+
279+
250280
/*
251281
* local variables:
252282
* mode: c

src/tmbstr.h

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ __attribute__((format(printf, 3, 4)))
7979
#endif
8080
;
8181

82+
TY_PRIVATE void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep);
83+
84+
8285
#ifdef __cplusplus
8386
} /* extern "C" */
8487
#endif

0 commit comments

Comments
 (0)