Differences From Artifact [dae29d5404]:
- File src/OFString.h — part of check-in [c7f0229795] at 2020-01-02 01:51:34 on branch trunk — Update copyright (user: js, size: 41046) [annotate] [blame] [check-ins using] [more...]
To Artifact [18fc9bbd71]:
- File
src/OFString.h
— part of check-in
[94f1f0f479]
at
2020-04-21 22:47:25
on branch trunk
— OFWindowsRegistryKey: Compatibility with Win XP
This requires a slight API change to OFWindowsRegistryKey, as the
previous API was depending on RegGetValueW(), which is not available on
Windows XP. (user: js, size: 41484) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * the packaging of this file. * * 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 __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif | > > > | | > | | | > > > > > > | 10 11 12 13 14 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 | * the packaging of this file. * * 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 #include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #include <stdarg.h> #include <stdint.h> #ifdef OF_HAVE_INTTYPES_H # include <inttypes.h> #endif #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 typedef uint_least16_t of_char16_t; typedef uint_least32_t of_char32_t; |
︙ | ︙ | |||
106 107 108 109 110 111 112 113 114 115 116 117 118 119 | * @param line The current line * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^of_string_line_enumeration_block_t)(OFString *line, bool *stop); #endif @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; @class OFURL; /*! * @class OFString OFString.h ObjFW/OFString.h * | > | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | * @param line The current line * @param stop A pointer to a variable that can be set to true to stop the * 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; /*! * @class OFString OFString.h ObjFW/OFString.h * |
︙ | ︙ | |||
161 162 163 164 165 166 167 | /*! * @brief The decimal value of the string as an `intmax_t`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an | | | | | | | 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | /*! * @brief The decimal value of the string as an `intmax_t`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into an `intmax_t`, an * @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) intmax_t decimalValue; /*! * @brief The hexadecimal value of the string as an `uintmax_t`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into an `uintmax_t`, an * @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) uintmax_t hexadecimalValue; /*! * @brief The octal value of the string as an `uintmax_t`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into an `uintmax_t`, an * @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) uintmax_t octalValue; /*! * @brief The float value of the string as a float. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. */ @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. */ @property (readonly, nonatomic) double doubleValue; /*! * @brief The string as an array of Unicode characters. * * The result is valid until the autorelease pool is released. If you want to |
︙ | ︙ | |||
260 261 262 263 264 265 266 | @property (readonly, nonatomic) OFString *stringByDeletingTrailingWhitespaces; /*! * @brief The string with leading and trailing whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingEnclosingWhitespaces; | | | > > > > > > > > | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | @property (readonly, nonatomic) OFString *stringByDeletingTrailingWhitespaces; /*! * @brief The string with leading and trailing whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingEnclosingWhitespaces; # ifdef OF_HAVE_UNICODE_TABLES /*! * @brief The string in Unicode Normalization Form D (NFD). */ @property (readonly, nonatomic) OFString *decomposedStringWithCanonicalMapping; /*! * @brief The string in Unicode Normalization Form KD (NFKD). */ @property (readonly, nonatomic) OFString *decomposedStringWithCompatibilityMapping; # endif # ifdef OF_WINDOWS /*! * @brief The string with the Windows Environment Strings expanded. */ @property (readonly, nonatomic) OFString *stringByExpandingWindowsEnvironmentStrings; # endif /*! * @brief Creates a new OFString. * * @return A new, autoreleased OFString */ + (instancetype)string; |
︙ | ︙ | |||
487 488 489 490 491 492 493 | * `const of_unichar_t *`. * * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; | | | | | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | * `const of_unichar_t *`. * * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; # 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 * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path; /*! * @brief Creates a new OFString with the contents of the specified file in the * specified encoding. * * @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; # endif # 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. * * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP * headers. If it could not detect the encoding using the HTTP headers, it tries |
︙ | ︙ | |||
534 535 536 537 538 539 540 | * * @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; | | | 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | * * @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; # endif /*! * @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 |
︙ | ︙ | |||
761 762 763 764 765 766 767 | * @param format A string used as format to initialize the OFString * @param arguments The arguments used in the format string * @return An initialized OFString */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; | | | | 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | * @param format A string used as format to initialize the OFString * @param arguments The arguments used in the format string * @return An initialized OFString */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; # 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 * @return An initialized OFString */ - (instancetype)initWithContentsOfFile: (OFString *)path; /*! * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @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; # endif /*! * @brief Initializes an already allocated OFString with the contents of the * specified URL. * * If the URL's scheme is file, it tries UTF-8 encoding. * |
︙ | ︙ | |||
1166 1167 1168 1169 1170 1171 1172 | * @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; | | | | | > | | > | | | | | | | | | | > | > > | 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 | * @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; # 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 */ - (void)writeToFile: (OFString *)path; /*! * @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 */ - (void)writeToFile: (OFString *)path encoding: (of_string_encoding_t)encoding; # endif /*! * @brief Writes the string to the specified URL using UTF-8 encoding. * * @param URL The URL to write to */ - (void)writeToURL: (OFURL *)URL; /*! * @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; # 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 @end #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); extern size_t of_string_utf8_encode(of_unichar_t, char *); extern ssize_t of_string_utf8_decode(const char *, size_t, of_unichar_t *); extern size_t of_string_utf16_length(const of_char16_t *); extern size_t of_string_utf32_length(const of_char32_t *); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #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 * @compatibility_alias does not work if @class has been used before. * For some reason, this makes Clang refer to OFString for string box literals * and not to NSString (which would result in a linker error, but would be the * correct behavior). * * TODO: Submit a patch for Clang that makes the boxing classes configurable! */ @interface NSString: OFString @end #endif #endif |