@@ -63,46 +63,46 @@ typedef OFChar32 OFUnichar; /** * @brief The encoding of a string. */ -typedef enum of_string_encoding_t { +typedef enum OFStringEncoding { /* * UTF-8 *has* to be 0, so that if the current @ref OFLocale is * `nil`, `[OFLocale encoding]` returns UTF-8. */ /** UTF-8 */ - OF_STRING_ENCODING_UTF_8, + OFStringEncodingUTF8, /** ASCII */ - OF_STRING_ENCODING_ASCII, + OFStringEncodingASCII, /** ISO 8859-1 */ - OF_STRING_ENCODING_ISO_8859_1, + OFStringEncodingISO8859_1, /** ISO 8859-2 */ - OF_STRING_ENCODING_ISO_8859_2, + OFStringEncodingISO8859_2, /** ISO 8859-3 */ - OF_STRING_ENCODING_ISO_8859_3, + OFStringEncodingISO8859_3, /** ISO 8859-15 */ - OF_STRING_ENCODING_ISO_8859_15, + OFStringEncodingISO8859_15, /** Windows-1251 */ - OF_STRING_ENCODING_WINDOWS_1251, + OFStringEncodingWindows1251, /** Windows-1252 */ - OF_STRING_ENCODING_WINDOWS_1252, + OFStringEncodingWindows1252, /** Codepage 437 */ - OF_STRING_ENCODING_CODEPAGE_437, + OFStringEncodingCodepage437, /** Codepage 850 */ - OF_STRING_ENCODING_CODEPAGE_850, + OFStringEncodingCodepage850, /** Codepage 858 */ - OF_STRING_ENCODING_CODEPAGE_858, + OFStringEncodingCodepage858, /** Mac OS Roman */ - OF_STRING_ENCODING_MAC_ROMAN, + OFStringEncodingMacRoman, /** KOI8-R */ - OF_STRING_ENCODING_KOI8_R, + OFStringEncodingKOI8R, /** KOI8-U */ - OF_STRING_ENCODING_KOI8_U, + OFStringEncodingKOI8U, /** Try to automatically detect the encoding */ - OF_STRING_ENCODING_AUTODETECT = 0xFF -} of_string_encoding_t; + OFStringEncodingAutodetect = 0xFF +} OFStringEncoding; enum { OF_STRING_SEARCH_BACKWARDS = 1, OF_STRING_SKIP_EMPTY = 2 }; @@ -349,11 +349,11 @@ * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return A new autoreleased OFString */ + (instancetype)stringWithCString: (const char *)cString - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Creates a new OFString from a C string with the specified encoding * and length. * @@ -361,11 +361,11 @@ * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return A new autoreleased OFString */ + (instancetype)stringWithCString: (const char *)cString - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Creates a new OFString from OFData with the specified encoding. * @@ -372,11 +372,11 @@ * @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 */ + (instancetype)stringWithData: (OFData *)data - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Creates a new OFString from another string. * * @param string A string to initialize the OFString with @@ -512,11 +512,11 @@ * @param path The path to the file * @param encoding The encoding of the file * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; # endif /** * @brief Creates a new OFString with the contents of the specified URL. * @@ -538,11 +538,11 @@ * @param URL The URL to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * @@ -606,11 +606,11 @@ * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return An initialized OFString */ - (instancetype)initWithCString: (const char *)cString - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString from a C string with the * specified encoding and length. * @@ -618,11 +618,11 @@ * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return An initialized OFString */ - (instancetype)initWithCString: (const char *)cString - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Initializes an already allocated OFString from OFData with the * specified encoding. @@ -630,11 +630,11 @@ * @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 */ - (instancetype)initWithData: (OFData *)data - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString with another string. * * @param string A string to initialize the OFString with @@ -784,11 +784,11 @@ * @param path The path to the file * @param encoding The encoding of the file * @return An initialized OFString */ - (instancetype)initWithContentsOfFile: (OFString *)path - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; # endif /** * @brief Initializes an already allocated OFString with the contents of the * specified URL. @@ -811,11 +811,11 @@ * @param URL The URL to the contents for the string * @param encoding The encoding to assume * @return An initialized OFString */ - (instancetype)initWithContentsOfURL: (OFURL *)URL - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding. * @@ -826,11 +826,11 @@ * @return The number of bytes written into the C string, without the * terminating zero */ - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding, replacing characters that cannot be represented in the * specified encoding with a question mark. @@ -842,11 +842,11 @@ * @return The number of bytes written into the C string, without the * terminating zero */ - (size_t)getLossyCString: (char *)cString maxLength: (size_t)maxLength - encoding: (of_string_encoding_t)encoding; + encoding: (OFStringEncoding)encoding; /** * @brief Returns the OFString as a C string in the specified encoding. * * The result is valid until the autorelease pool is released. If you want to @@ -854,11 +854,11 @@ * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ -- (const char *)cStringWithEncoding: (of_string_encoding_t)encoding +- (const char *)cStringWithEncoding: (OFStringEncoding)encoding OF_RETURNS_INNER_POINTER; /** * @brief Returns the OFString as a C string in the specified encoding, * replacing characters that cannot be represented in the specified @@ -869,21 +869,21 @@ * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ -- (const char *)lossyCStringWithEncoding: (of_string_encoding_t)encoding +- (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding OF_RETURNS_INNER_POINTER; /** * @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. */ -- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding; +- (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding; /** * @brief Compares the string to another string. * * @param string The string to compare the string to @@ -1228,11 +1228,11 @@ * @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 */ -- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding; +- (OFData *)dataWithEncoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_FILES /** * @brief Writes the string into the specified file using UTF-8 encoding. * @@ -1245,11 +1245,11 @@ * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file */ -- (void)writeToFile: (OFString *)path encoding: (of_string_encoding_t)encoding; +- (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Writes the string to the specified URL using UTF-8 encoding. * @@ -1261,11 +1261,11 @@ * @brief Writes the string to the specified URL using the specified encoding. * * @param URL The URL to write to * @param encoding The encoding to use to write the string to the URL */ -- (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; +- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_BLOCKS /** * Enumerates all lines in the receiver using the specified block. * @@ -1277,12 +1277,30 @@ #endif #ifdef __cplusplus extern "C" { #endif -extern of_string_encoding_t of_string_parse_encoding(OFString *); -extern OFString *_Nullable of_string_name_of_encoding(of_string_encoding_t); +/** + * @brief Parses the specified string encoding name and returns the + * OFStringEncoding for it. + * + * Throws @ref OFInvalidArgumentException if the specified name is not a valid + * encoding name. + * + * @param name The name to parse as a string encoding + * @return The OFStringEncoding for the specified name + */ +extern OFStringEncoding OFParseStringEncodingName(OFString *name); + +/** + * @brief Returns the name of the specified OFStringEncoding. + * + * @param encoding The encoding for which to return the name + * @return The name of the specified OFStringEncoding + */ +extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding); + extern size_t of_string_utf8_encode(OFUnichar, char *); extern ssize_t of_string_utf8_decode(const char *, size_t, OFUnichar *); extern size_t of_string_utf16_length(const OFChar16 *); extern size_t of_string_utf32_length(const OFChar32 *); #ifdef __cplusplus