15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
* file.
*/
#import "OFString.h"
OF_ASSUME_NONNULL_BEGIN
/*! @file */
#ifdef __cplusplus
extern "C" {
#endif
extern int _OFString_XMLUnescaping_reference;
#ifdef __cplusplus
}
#endif
#ifdef OF_HAVE_BLOCKS
/*!
* @brief A block which is called to replace unknown XML entities in an XML
* string.
*
* @param string The XML string which contains an unknown entity
* @param entity The XML entity which is unknown
* @return A replacement string for the unknown entity
*/
typedef OFString *_Nullable (^of_string_xml_unescaping_block_t)(
OFString *string, OFString *entity);
#endif
/*!
* @protocol OFStringXMLUnescapingDelegate OFString.h ObjFW/OFString.h
*
* @brief A protocol that needs to be implemented by delegates for
* stringByXMLUnescapingWithHandler:.
*/
@protocol OFStringXMLUnescapingDelegate <OFObject>
/*!
* @brief This callback is called when an unknown entity was found while trying
* to unescape XML.
*
* The callback is supposed to return a substitution for the entity or `nil` if
* it is unknown to the callback as well, in which case an exception will be
* thrown.
*
* @param string The string which contains the unknown entity
* @param entity The name of the entity that is unknown
* @return A substitution for the entity or `nil`
*/
- (nullable OFString *)string: (OFString *)string
containsUnknownEntityNamed: (OFString *)entity;
@end
@interface OFString (XMLUnescaping)
/*!
* @brief The string with XML entities unescapted.
*/
@property (readonly, nonatomic) OFString *stringByXMLUnescaping;
/*!
* @brief Unescapes XML in the string and uses the specified delegate for
* unknown entities.
*
* @param delegate An OFXMLUnescapingDelegate as a handler for unknown entities
*/
- (OFString *)stringByXMLUnescapingWithDelegate:
(nullable id <OFStringXMLUnescapingDelegate>)delegate;
#ifdef OF_HAVE_BLOCKS
/*!
* @brief Unescapes XML in the string and uses the specified block for unknown
* entities.
*
* @param block A block which handles unknown entities
*/
- (OFString *)stringByXMLUnescapingWithBlock:
(of_string_xml_unescaping_block_t)block;
#endif
@end
OF_ASSUME_NONNULL_END
|
|
|
|
|
|
|
|
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
* file.
*/
#import "OFString.h"
OF_ASSUME_NONNULL_BEGIN
/** @file */
#ifdef __cplusplus
extern "C" {
#endif
extern int _OFString_XMLUnescaping_reference;
#ifdef __cplusplus
}
#endif
#ifdef OF_HAVE_BLOCKS
/**
* @brief A block which is called to replace unknown XML entities in an XML
* string.
*
* @param string The XML string which contains an unknown entity
* @param entity The XML entity which is unknown
* @return A replacement string for the unknown entity
*/
typedef OFString *_Nullable (^of_string_xml_unescaping_block_t)(
OFString *string, OFString *entity);
#endif
/**
* @protocol OFStringXMLUnescapingDelegate OFString.h ObjFW/OFString.h
*
* @brief A protocol that needs to be implemented by delegates for
* stringByXMLUnescapingWithHandler:.
*/
@protocol OFStringXMLUnescapingDelegate <OFObject>
/**
* @brief This callback is called when an unknown entity was found while trying
* to unescape XML.
*
* The callback is supposed to return a substitution for the entity or `nil` if
* it is unknown to the callback as well, in which case an exception will be
* thrown.
*
* @param string The string which contains the unknown entity
* @param entity The name of the entity that is unknown
* @return A substitution for the entity or `nil`
*/
- (nullable OFString *)string: (OFString *)string
containsUnknownEntityNamed: (OFString *)entity;
@end
@interface OFString (XMLUnescaping)
/**
* @brief The string with XML entities unescapted.
*/
@property (readonly, nonatomic) OFString *stringByXMLUnescaping;
/**
* @brief Unescapes XML in the string and uses the specified delegate for
* unknown entities.
*
* @param delegate An OFXMLUnescapingDelegate as a handler for unknown entities
*/
- (OFString *)stringByXMLUnescapingWithDelegate:
(nullable id <OFStringXMLUnescapingDelegate>)delegate;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Unescapes XML in the string and uses the specified block for unknown
* entities.
*
* @param block A block which handles unknown entities
*/
- (OFString *)stringByXMLUnescapingWithBlock:
(of_string_xml_unescaping_block_t)block;
#endif
@end
OF_ASSUME_NONNULL_END
|