Index: src/OFString+XMLUnescaping.h ================================================================== --- src/OFString+XMLUnescaping.h +++ src/OFString+XMLUnescaping.h @@ -72,10 +72,12 @@ /** * @brief Unescapes XML in the string and uses the specified delegate for * unknown entities. * * @param delegate An OFXMLUnescapingDelegate as a handler for unknown entities + * @throw OFInvalidFormatException The string is not a valid XML string + * @throw OFUnknownXMLEntityException The string contains unknown XML entities */ - (OFString *)stringByXMLUnescapingWithDelegate: (nullable id )delegate; #ifdef OF_HAVE_BLOCKS @@ -82,11 +84,13 @@ /** * @brief Unescapes XML in the string and uses the specified block for unknown * entities. * * @param block A block which handles unknown entities + * @throw OFInvalidFormatException The string is not a valid XML string + * @throw OFUnknownXMLEntityException The string contains unknown XML entities */ - (OFString *)stringByXMLUnescapingWithBlock: (OFStringXMLUnescapingBlock)block; #endif @end OF_ASSUME_NONNULL_END Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -210,20 +210,20 @@ @property (readonly, nonatomic) unsigned long long unsignedLongLongValue; /** * @brief The float value of the string as a float. * - * If the string contains any non-number characters, an - * @ref OFInvalidFormatException is thrown. + * @throw OFInvalidFormatException The string cannot be parsed as a `float` + * @throw OFOutOfRangeException The value cannot be represented as a `float` */ @property (readonly, nonatomic) float floatValue; /** * @brief The double value of the string as a double. * - * If the string contains any non-number characters, an - * @ref OFInvalidFormatException is thrown. + * @throw OFInvalidFormatException The string cannot be parsed as a `double` + * @throw OFOutOfRangeException The value cannot be represented as a `double` */ @property (readonly, nonatomic) double doubleValue; /** * @brief The string as an array of Unicode characters. @@ -312,10 +312,11 @@ /** * @brief Creates a new OFString from a UTF-8 encoded C string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8String: (const char *)UTF8String; /** * @brief Creates a new OFString from a UTF-8 encoded C string with the @@ -322,10 +323,11 @@ * specified length. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** @@ -339,10 +341,11 @@ * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param freeWhenDone Whether to free the C string when the OFString gets * deallocated * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone; /** @@ -357,10 +360,11 @@ * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @param freeWhenDone Whether to free the C string when the OFString gets * deallocated * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone; @@ -368,10 +372,11 @@ * @brief Creates a new OFString from a C string with the specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** @@ -380,10 +385,11 @@ * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; @@ -391,10 +397,11 @@ * @brief Creates a new OFString from OFData with the specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** @@ -419,10 +426,11 @@ /** * @brief Creates a new OFString from a UTF-16 encoded string. * * @param string A zero-terminated UTF-16 string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string; /** * @brief Creates a new OFString from a UTF-16 encoded string with the @@ -429,10 +437,11 @@ * specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** @@ -440,10 +449,11 @@ * specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** @@ -453,10 +463,11 @@ * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; @@ -511,10 +522,13 @@ * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString + * @throw OFInvalidFormatException The specified format is invalid + * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 + * encoding */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; # ifdef OF_HAVE_FILES /** @@ -521,10 +535,11 @@ * @brief Creates a new OFString with the contents of the specified UTF-8 * encoded file. * * @param path The path to the file * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithContentsOfFile: (OFString *)path; /** * @brief Creates a new OFString with the contents of the specified file in the @@ -531,10 +546,11 @@ * specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif @@ -547,10 +563,11 @@ * headers. If it could not detect the encoding using the HTTP headers, it tries * UTF-8. * * @param URI The URI to the contents for the string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the expected encoding */ + (instancetype)stringWithContentsOfURI: (OFURI *)URI; /** * @brief Creates a new OFString with the contents of the specified URI in the @@ -557,10 +574,11 @@ * specified encoding. * * @param URI The URI to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; /** @@ -567,10 +585,11 @@ * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8String: (const char *)UTF8String; /** * @brief Initializes an already allocated OFString from a UTF-8 encoded C @@ -577,10 +596,11 @@ * string with the specified length. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** @@ -594,10 +614,11 @@ * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param freeWhenDone Whether to free the C string when it is not needed * anymore * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone; /** @@ -613,10 +634,11 @@ * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @param freeWhenDone Whether to free the C string when it is not needed * anymore * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone; @@ -625,10 +647,11 @@ * specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** @@ -637,10 +660,11 @@ * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; @@ -649,10 +673,11 @@ * specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** @@ -677,10 +702,11 @@ /** * @brief Initializes an already allocated OFString with a UTF-16 string. * * @param string A zero-terminated UTF-16 string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string; /** * @brief Initializes an already allocated OFString with a UTF-16 string with @@ -687,10 +713,11 @@ * the specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** @@ -698,10 +725,11 @@ * assuming the specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** @@ -711,10 +739,11 @@ * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; @@ -769,10 +798,13 @@ * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return An initialized OFString + * @throw OFInvalidFormatException The specified format is invalid + * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 + * encoding */ - (instancetype)initWithFormat: (OFConstantString *)format, ...; /** * @brief Initializes an already allocated OFString with a format string. @@ -782,10 +814,13 @@ * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @param arguments The arguments used in the format string * @return An initialized OFString + * @throw OFInvalidFormatException The specified format is invalid + * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 + * encoding */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; # ifdef OF_HAVE_FILES @@ -793,10 +828,11 @@ * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @param path The path to the file * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithContentsOfFile: (OFString *)path; /** * @brief Initializes an already allocated OFString with the contents of the @@ -803,10 +839,11 @@ * specified file in the specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif @@ -820,10 +857,11 @@ * headers. If it could not detect the encoding using the HTTP headers, it tries * UTF-8. * * @param URI The URI to the contents for the string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the expected encoding */ - (instancetype)initWithContentsOfURI: (OFURI *)URI; /** * @brief Initializes an already allocated OFString with the contents of the @@ -830,10 +868,11 @@ * specified URI in the specified encoding. * * @param URI The URI to the contents for the string * @param encoding The encoding to assume * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; /** @@ -844,10 +883,12 @@ * @param maxLength The maximum number of bytes to write into the C string, * including the terminating zero * @param encoding The encoding to use for writing into the C string * @return The number of bytes written into the C string, without the * terminating zero + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding; @@ -874,10 +915,12 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (const char *)cStringWithEncoding: (OFStringEncoding)encoding OF_RETURNS_INNER_POINTER; /** @@ -899,10 +942,12 @@ * @brief Returns the number of bytes the string needs in the specified * encoding. * * @param encoding The encoding for the string * @return The number of bytes the string needs in the specified encoding. + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding; /** * @brief Compares the string to another string. @@ -1049,10 +1094,12 @@ * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The value of the string in the specified base + * @throw OFInvalidFormatException The string cannot be parsed as a `long long` + * @throw OFOutOfRangeException The value cannot be represented as a `long long` */ - (long long)longLongValueWithBase: (unsigned char)base; /** * @brief The value of the string in the specified base as an @@ -1069,10 +1116,14 @@ * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The value of the string in the specified base + * @throw OFInvalidFormatException The string cannot be parsed as an + * `unsigned long long` + * @throw OFOutOfRangeException The value cannot be represented as an + * `unsigned long long` */ - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base; /** * @brief Creates a new string by appending another string. @@ -1085,19 +1136,25 @@ /** * @brief Creates a new string by appending the specified format. * * @param format A format string which generates the string to append * @return A new, autoreleased OFString with the specified format appended + * @throw OFInvalidEncodingException The string was not properly UTF-8-encoded + * after formatting it + * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ...; /** * @brief Creates a new string by appending the specified format. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @return A new, autoreleased OFString with the specified format appended + * @throw OFInvalidEncodingException The string was not properly UTF-8-encoded + * after formatting it + * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; /** @@ -1197,10 +1254,11 @@ * * The returned string is null-terminated. * * @param byteOrder The byte order for the UTF-16 encoding * @return The string in UTF-16 encoding with the specified byte order + * @throw OFInvalidEncodingException The string cannot be represented in UTF-16 */ - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; /** @@ -1221,10 +1279,12 @@ /** * @brief Returns the string as OFData with the specified encoding. * * @param encoding The encoding to use for the returned OFData * @return The string as OFData with the specified encoding + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (OFData *)dataWithEncoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_FILES /** @@ -1238,10 +1298,12 @@ * @brief Writes the string into the specified file using the specified * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** @@ -1254,10 +1316,12 @@ /** * @brief Writes the string to the specified URI using the specified encoding. * * @param URI The URI to write to * @param encoding The encoding to use to write the string to the URI + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_BLOCKS /**