@@ -12,19 +12,22 @@ * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ + +#ifndef OBJFW_OF_STRING_H +#define OBJFW_OF_STRING_H #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif -#import "objfw-defs.h" +#include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include #endif @@ -32,20 +35,27 @@ #include #ifdef OF_HAVE_INTTYPES_H # include #endif -#import "OFObject.h" -#import "OFSerialization.h" -#import "OFJSONRepresentation.h" -#import "OFMessagePackRepresentation.h" +#include "OFObject.h" +#ifdef __OBJC__ +# import "OFSerialization.h" +# import "OFJSONRepresentation.h" +# import "OFMessagePackRepresentation.h" +#endif OF_ASSUME_NONNULL_BEGIN /*! @file */ +#ifdef __OBJC__ @class OFConstantString; +@class OFString; +#else +typedef void OFString; +#endif #if defined(__cplusplus) && __cplusplus >= 201103L typedef char16_t of_char16_t; typedef char32_t of_char32_t; #else @@ -108,10 +118,11 @@ * enumeration */ typedef void (^of_string_line_enumeration_block_t)(OFString *line, bool *stop); #endif +#ifdef __OBJC__ @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; @class OFURL; /*! @@ -262,11 +273,11 @@ /*! * @brief The string with leading and trailing whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingEnclosingWhitespaces; -#ifdef OF_HAVE_UNICODE_TABLES +# ifdef OF_HAVE_UNICODE_TABLES /*! * @brief The string in Unicode Normalization Form D (NFD). */ @property (readonly, nonatomic) OFString *decomposedStringWithCanonicalMapping; @@ -273,11 +284,11 @@ /*! * @brief The string in Unicode Normalization Form KD (NFKD). */ @property (readonly, nonatomic) OFString *decomposedStringWithCompatibilityMapping; -#endif +# endif /*! * @brief Creates a new OFString. * * @return A new, autoreleased OFString @@ -489,11 +500,11 @@ * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; -#ifdef OF_HAVE_FILES +# ifdef OF_HAVE_FILES /*! * @brief Creates a new OFString with the contents of the specified UTF-8 * encoded file. * * @param path The path to the file @@ -509,13 +520,13 @@ * @param encoding The encoding of the file * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (of_string_encoding_t)encoding; -#endif +# endif -#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS) +# if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS) /*! * @brief Creates a new OFString with the contents of the specified URL. * * If the URL's scheme is file, it tries UTF-8 encoding. * @@ -536,11 +547,11 @@ * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; -#endif +# endif /*! * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * @@ -763,11 +774,11 @@ * @return An initialized OFString */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; -#ifdef OF_HAVE_FILES +# ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @param path The path to the file @@ -783,11 +794,11 @@ * @param encoding The encoding of the file * @return An initialized OFString */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (of_string_encoding_t)encoding; -#endif +# endif /*! * @brief Initializes an already allocated OFString with the contents of the * specified URL. * @@ -1168,11 +1179,11 @@ * @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; -#ifdef OF_HAVE_FILES +# ifdef OF_HAVE_FILES /*! * @brief Writes the string into the specified file using UTF-8 encoding. * * @param path The path of the file to write to */ @@ -1185,11 +1196,11 @@ * @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; -#endif +# endif /*! * @brief Writes the string to the specified URL using UTF-8 encoding. * * @param URL The URL to write to @@ -1203,19 +1214,20 @@ * @param encoding The encoding to use to write the string to the URL */ - (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS /*! * Enumerates all lines in the receiver using the specified block. * * @brief block The block to call for each line */ - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block; -#endif +# endif @end +#endif #ifdef __cplusplus extern "C" { #endif extern of_string_encoding_t of_string_parse_encoding(OFString *); @@ -1228,24 +1240,26 @@ } #endif OF_ASSUME_NONNULL_END -#import "OFConstantString.h" -#import "OFMutableString.h" -#import "OFString+CryptoHashing.h" -#import "OFString+JSONValue.h" -#ifdef OF_HAVE_FILES -# import "OFString+PathAdditions.h" -#endif -#import "OFString+PropertyListValue.h" -#import "OFString+Serialization.h" -#import "OFString+URLEncoding.h" -#import "OFString+XMLEscaping.h" -#import "OFString+XMLUnescaping.h" - -#if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) +#include "OFConstantString.h" +#include "OFMutableString.h" +#ifdef __OBJC__ +# import "OFString+CryptoHashing.h" +# import "OFString+JSONValue.h" +# ifdef OF_HAVE_FILES +# import "OFString+PathAdditions.h" +# endif +# import "OFString+PropertyListValue.h" +# import "OFString+Serialization.h" +# import "OFString+URLEncoding.h" +# import "OFString+XMLEscaping.h" +# import "OFString+XMLUnescaping.h" +#endif + +#if defined(__OBJC__) && !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* * Very *ugly* hack required for string boxing literals to work. * * This hack is needed in order to work with `@class NSString` from Apple's * objc/NSString.h - which is included when using modules - as @@ -1256,6 +1270,8 @@ * * TODO: Submit a patch for Clang that makes the boxing classes configurable! */ @interface NSString: OFString @end +#endif + #endif