From 8ddc0105f9d8d4ec5da250dc870d1b1f074e997d Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Sun, 19 Nov 2017 10:21:46 -0500 Subject: [PATCH] Add missing iterators for recently added options mute and priority attributes. --- include/tidy.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/attrs.c | 28 +++++++++++++++++++++++++++ src/attrs.h | 6 ++++++ src/message.c | 28 +++++++++++++++++++++++++++ src/message.h | 13 +++++++++++++ src/tidylib.c | 39 +++++++++++++++++++++++++++++++++++++ 6 files changed, 166 insertions(+) diff --git a/include/tidy.h b/include/tidy.h index d0c05a3..94e823b 100644 --- a/include/tidy.h +++ b/include/tidy.h @@ -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 ** @{ diff --git a/src/attrs.c b/src/attrs.c index f9f950c..112f5d1 100644 --- a/src/attrs.c +++ b/src/attrs.c @@ -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 ) { diff --git a/src/attrs.h b/src/attrs.h index 3a78a0f..befdcd1 100644 --- a/src/attrs.h +++ b/src/attrs.h @@ -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 ); */ diff --git a/src/message.c b/src/message.c index c8559fd..1040e3a 100644 --- a/src/message.c +++ b/src/message.c @@ -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 *********************************************************************/ diff --git a/src/message.h b/src/message.h index 20ecdde..b093d1d 100644 --- a/src/message.h +++ b/src/message.h @@ -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 */ diff --git a/src/tidylib.c b/src/tidylib.c index da34027..1a90322 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -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 );