Externalize the TidyReportFilter3 error codes, and provide iterators to loop through them.
This commit is contained in:
parent
b4d2bdf3bf
commit
bc1e54d5b5
|
@ -223,16 +223,6 @@ static const tidyLocaleMapItem localeMappings[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the mapping for LibTidy users to map between an opaque key
|
|
||||||
* and an error message value. See `tidyErrorFilterKeys[]`, below.
|
|
||||||
*/
|
|
||||||
typedef struct tidyErrorFilterKeyItem {
|
|
||||||
ctmbstr key;
|
|
||||||
int value;
|
|
||||||
} tidyErrorFilterKeyItem;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LibTidy users may want to use `TidyReportFilter3` to enable their own
|
* LibTidy users may want to use `TidyReportFilter3` to enable their own
|
||||||
* localization lookup features. Because Tidy's errors codes are enums the
|
* localization lookup features. Because Tidy's errors codes are enums the
|
||||||
|
@ -906,3 +896,53 @@ ctmbstr getNextInstalledLanguage( TidyIterator* iter )
|
||||||
*iter = (TidyIterator)( itemIndex <= TY_(tidyInstalledLanguageListSize)() ? itemIndex : (size_t)0 );
|
*iter = (TidyIterator)( itemIndex <= TY_(tidyInstalledLanguageListSize)() ? itemIndex : (size_t)0 );
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the number of error codes used by Tidy.
|
||||||
|
*/
|
||||||
|
const uint TY_(tidyErrorCodeListSize)()
|
||||||
|
{
|
||||||
|
static uint array_size = 0;
|
||||||
|
|
||||||
|
if ( array_size == 0 )
|
||||||
|
{
|
||||||
|
while ( tidyErrorFilterKeysStruct[array_size].key ) {
|
||||||
|
array_size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the TidyIterator to point to the first item
|
||||||
|
* in Tidy's list of error codes that can be return with
|
||||||
|
* `TidyReportFilter3`.
|
||||||
|
* Items can be retrieved with getNextErrorCode();
|
||||||
|
*/
|
||||||
|
TidyIterator getErrorCodeList()
|
||||||
|
{
|
||||||
|
return (TidyIterator)(size_t)1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next error code.
|
||||||
|
*/
|
||||||
|
const tidyErrorFilterKeyItem *getNextErrorCode( TidyIterator* iter )
|
||||||
|
{
|
||||||
|
const tidyErrorFilterKeyItem *item = NULL;
|
||||||
|
size_t itemIndex;
|
||||||
|
assert( iter != NULL );
|
||||||
|
|
||||||
|
itemIndex = (size_t)*iter;
|
||||||
|
|
||||||
|
if ( itemIndex > 0 && itemIndex <= TY_(tidyErrorCodeListSize)() )
|
||||||
|
{
|
||||||
|
item = &tidyErrorFilterKeysStruct[itemIndex - 1];
|
||||||
|
itemIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*iter = (TidyIterator)( itemIndex <= TY_(tidyErrorCodeListSize)() ? itemIndex : (size_t)0 );
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
|
@ -66,6 +66,22 @@ typedef struct tidyLocaleMapItem {
|
||||||
} tidyLocaleMapItem;
|
} tidyLocaleMapItem;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The function getNextErrorCode() returns pointers to this type; it gives
|
||||||
|
* LibTidy implementors the ability to know what errors can be returned
|
||||||
|
* via `TidyReportFilter3`.
|
||||||
|
* Provides the mapping for LibTidy users to map between an opaque key
|
||||||
|
* and an error message value. See `tidyErrorFilterKeys[]` in `language.c`.
|
||||||
|
* The `key` string is guaranteed by the API (unless deleted entirely). The
|
||||||
|
* `value` is suitable for use in looking up Tidy's strings, but its value
|
||||||
|
* is not guaranteed between releases.
|
||||||
|
*/
|
||||||
|
typedef struct tidyErrorFilterKeyItem {
|
||||||
|
ctmbstr key;
|
||||||
|
int value;
|
||||||
|
} tidyErrorFilterKeyItem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines all of the possible dictionary keys.
|
* Defines all of the possible dictionary keys.
|
||||||
* The starting value is arbitrary but must prevent overlaps
|
* The starting value is arbitrary but must prevent overlaps
|
||||||
|
@ -296,6 +312,20 @@ TidyIterator getInstalledLanguageList();
|
||||||
ctmbstr getNextInstalledLanguage( TidyIterator* iter );
|
ctmbstr getNextInstalledLanguage( TidyIterator* iter );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the TidyIterator to point to the first item
|
||||||
|
* in Tidy's list of error codes that can be return with
|
||||||
|
* `TidyReportFilter3`.
|
||||||
|
* Items can be retrieved with getNextErrorCode();
|
||||||
|
*/
|
||||||
|
TidyIterator getErrorCodeList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next error code.
|
||||||
|
*/
|
||||||
|
const tidyErrorFilterKeyItem *getNextErrorCode( TidyIterator* iter );
|
||||||
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* language_h */
|
#endif /* language_h */
|
||||||
|
|
Loading…
Reference in a new issue