Add missing iterators for recently added options mute and priority attributes.

This commit is contained in:
Jim Derry 2017-11-19 10:21:46 -05:00
parent 7105dbe0ee
commit 8ddc0105f9
6 changed files with 166 additions and 0 deletions

View file

@ -933,6 +933,58 @@ TIDY_EXPORT ctmbstr TIDY_CALL tidyOptGetNextDeclTag(TidyDoc tdoc, /*
TidyIterator* iter /**< The TidyIterator (initiated with tidyOptGetDeclTagList()) token. */
);
/** Initiates an iterator for a list of priority attributes. This iterator
** allows you to iterate through all of the priority attributes defined with
** the `priority-attributes` configuration option. In order to iterate through
** the attributes, initiate the iterator with this function, and then use
** tidyOptGetNextPriorityAttr() to retrieve the first and subsequent attributes.
** For example:
** @code{.c}
** TidyIterator itAttr = tidyOptGetPriorityAttrList( tdoc );
** while ( itAttr ) {
** printf("%s", tidyOptGetNextPriorityAttr( tdoc, &itAttr ));
** }
** @endcode
** @param tdoc An instance of a TidyDoc to query.
** @result Returns a TidyIterator, which is a token used to represent the
** current position in a list within LibTidy.
*/
TIDY_EXPORT TidyIterator TIDY_CALL tidyOptGetPriorityAttrList( TidyDoc tdoc );
/** Given a valid TidyIterator initiated with tidyOptGetPriorityAttrList(),
** returns a string representing a priority attribute.
** @result A string containing the next tag.
*/
TIDY_EXPORT ctmbstr TIDY_CALL tidyOptGetNextPriorityAttr(TidyDoc tdoc, /**< The tidy document to query. */
TidyIterator* iter /**< The TidyIterator (initiated with tidyOptGetPriorityAttrList()) token. */
);
/** Initiates an iterator for a list of muted messages. This iterator allows
** you to iterate through all of the priority attributes defined with the
** `mute` configuration option. In order to iterate through the list, initiate
** with this function, and then use tidyOptGetNextMutedMessage() to retrieve
** the first and subsequent attributes.
** For example:
** @code{.c}
** TidyIterator itAttr = tidyOptGetMutedMessageList( tdoc );
** while ( itAttr ) {
** printf("%s", tidyOptGetNextMutedMessage( tdoc, &itAttr ));
** }
** @endcode
** @param tdoc An instance of a TidyDoc to query.
** @result Returns a TidyIterator, which is a token used to represent the
** current position in a list within LibTidy.
*/
TIDY_EXPORT TidyIterator TIDY_CALL tidyOptGetMutedMessageList( TidyDoc tdoc );
/** Given a valid TidyIterator initiated with tidyOptGetMutedMessageList(),
** returns a string representing a muted message.
** @result A string containing the next tag.
*/
TIDY_EXPORT ctmbstr TIDY_CALL tidyOptGetNextMutedMessage(TidyDoc tdoc, /**< The tidy document to query. */
TidyIterator* iter /**< The TidyIterator (initiated with tidyOptGetMutedMessageList()) token. */
);
/** @}
** @name Option Documentation
** @{

View file

@ -807,6 +807,34 @@ void TY_(DefinePriorityAttribute)(TidyDocImpl* doc, ctmbstr name)
}
TidyIterator TY_(getPriorityAttrList)( TidyDocImpl* doc )
{
PriorityAttribs *priorities = &(doc->attribs.priorityAttribs);
size_t result = priorities->count > 0 ? 1 : 0;
return (TidyIterator) result;
}
ctmbstr TY_(getNextPriorityAttr)( TidyDocImpl* doc, TidyIterator* iter )
{
PriorityAttribs *priorities = &(doc->attribs.priorityAttribs);
size_t index;
ctmbstr result = NULL;
assert( iter != NULL );
index = (size_t)*iter;
if ( index > 0 && index < priorities->count )
{
result = priorities->list[index-1];
index++;
}
*iter = (TidyIterator) ( index <= priorities->count ? index : (size_t)0 );
return result;
}
static Bool CheckAttrType( TidyDocImpl* doc,
ctmbstr attrname, AttrCheck type )
{

View file

@ -98,6 +98,12 @@ AttVal* TY_(RepairAttrValue)(TidyDocImpl* doc, Node* node, ctmbstr name, ctmbstr
/* Add an item to the list of priority attributes to write first. */
void TY_(DefinePriorityAttribute)(TidyDocImpl* doc, ctmbstr name);
/* Start an iterator for priority attributes. */
TidyIterator TY_(getPriorityAttrList)( TidyDocImpl* doc );
/* Get the next priority attribute. */
ctmbstr TY_(getNextPriorityAttr)( TidyDocImpl* doc, TidyIterator* iter );
Bool TY_(IsUrl)( TidyDocImpl* doc, ctmbstr attrname );
/* Bool IsBool( TidyDocImpl* doc, ctmbstr attrname ); */

View file

@ -1360,6 +1360,34 @@ void TY_(DefineMutedMessage)(TidyDocImpl* doc, const TidyOptionImpl* opt, ctmbst
}
TidyIterator TY_(getMutedMessageList)( TidyDocImpl* doc )
{
TidyMutedMessages *list = &(doc->muted);
size_t result = list->count > 0 ? 1 : 0;
return (TidyIterator) result;
}
ctmbstr TY_(getNextMutedMessage)( TidyDocImpl* doc, TidyIterator* iter )
{
TidyMutedMessages *list = &(doc->muted);
size_t index;
ctmbstr result = NULL;
assert( iter != NULL );
index = (size_t)*iter;
if ( index > 0 && index < list->count )
{
result = TY_(tidyErrorCodeAsKey)(list->list[index-1]);
index++;
}
*iter = (TidyIterator) ( index <= list->count ? index : (size_t)0 );
return result;
}
/*********************************************************************
* Key Discovery
*********************************************************************/

View file

@ -210,6 +210,19 @@ void TY_(FreeMutedMessageList)( TidyDocImpl* doc );
*/
void TY_(DefineMutedMessage)( TidyDocImpl* doc, const TidyOptionImpl* opt, ctmbstr name );
/** Start an iterator for muted messages.
** @param doc The Tidy document.
** @returns Returns an iterator token.
*/
TidyIterator TY_(getMutedMessageList)( TidyDocImpl* doc );
/** Get the next priority attribute.
** @param doc The Tidy document.
** @param iter The iterator token.
** @returns The next priority attribute.
*/
ctmbstr TY_(getNextMutedMessage)( TidyDocImpl* doc, TidyIterator* iter );
/** @} message_muting group */

View file

@ -33,6 +33,7 @@
#include "utf8.h"
#include "mappedio.h"
#include "language.h"
#include "attrs.h"
#include "sprtf.h"
#if SUPPORT_LOCALIZATIONS
# include "locale.h"
@ -557,6 +558,44 @@ ctmbstr TIDY_CALL tidyOptGetNextDeclTag( TidyDoc tdoc, TidyOptionId optId,
return tagnam;
}
TidyIterator TIDY_CALL tidyOptGetPriorityAttrList( TidyDoc tdoc )
{
TidyDocImpl* impl = tidyDocToImpl( tdoc );
if ( impl )
return TY_(getPriorityAttrList)( impl );
return (TidyIterator) -1;
}
ctmbstr TIDY_CALL tidyOptGetNextPriorityAttr(TidyDoc tdoc, TidyIterator* iter )
{
TidyDocImpl* impl = tidyDocToImpl( tdoc );
ctmbstr result = NULL;
if ( impl )
result = TY_(getNextPriorityAttr)( impl, iter );
else if ( iter )
*iter = 0;
return result;
}
TidyIterator TIDY_CALL tidyOptGetMutedMessageList( TidyDoc tdoc )
{
TidyDocImpl* impl = tidyDocToImpl( tdoc );
if ( impl )
return TY_(getMutedMessageList)( impl );
return (TidyIterator) -1;
}
ctmbstr TIDY_CALL tidyOptGetNextMutedMessage(TidyDoc tdoc, TidyIterator* iter )
{
TidyDocImpl* impl = tidyDocToImpl( tdoc );
ctmbstr result = NULL;
if ( impl )
result = TY_(getNextMutedMessage)( impl, iter );
else if ( iter )
*iter = 0;
return result;
}
ctmbstr TIDY_CALL tidyOptGetDoc( TidyDoc ARG_UNUSED(tdoc), TidyOption opt )
{
const TidyOptionId optId = tidyOptGetId( opt );