ObjFW
src/OFString.h
00001 /*
00002  * Copyright (c) 2008, 2009, 2010, 2011
00003  *   Jonathan Schleifer <js@webkeks.org>
00004  *
00005  * All rights reserved.
00006  *
00007  * This file is part of ObjFW. It may be distributed under the terms of the
00008  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
00009  * the packaging of this file.
00010  *
00011  * Alternatively, it may be distributed under the terms of the GNU General
00012  * Public License, either version 2 or 3, which can be found in the file
00013  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
00014  * file.
00015  */
00016 
00017 #include <stdio.h>
00018 #include <stdarg.h>
00019 #include <inttypes.h>
00020 
00021 #import "OFObject.h"
00022 
00023 typedef uint32_t of_unichar_t;
00024 
00028 typedef enum of_string_encoding_t {
00029         OF_STRING_ENCODING_UTF_8,
00030         OF_STRING_ENCODING_ISO_8859_1,
00031         OF_STRING_ENCODING_ISO_8859_15,
00032         OF_STRING_ENCODING_WINDOWS_1252
00033 } of_string_encoding_t;
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 extern int of_string_check_utf8(const char*, size_t);
00039 extern size_t of_string_unicode_to_utf8(of_unichar_t, char*);
00040 extern size_t of_string_utf8_to_unicode(const char*, size_t, of_unichar_t*);
00041 extern size_t of_string_position_to_index(const char*, size_t);
00042 extern size_t of_string_index_to_position(const char*, size_t, size_t);
00043 #ifdef __cplusplus
00044 }
00045 #endif
00046 
00047 @class OFArray;
00048 @class OFURL;
00049 
00053 @interface OFString: OFObject <OFCopying, OFMutableCopying, OFComparing>
00054 {
00055         char   *string;
00056         size_t length;
00057         BOOL   isUTF8;
00058 }
00059 
00063 + string;
00064 
00071 + stringWithCString: (const char*)str;
00072 
00080 + stringWithCString: (const char*)str
00081            encoding: (of_string_encoding_t)encoding;
00082 
00092 + stringWithCString: (const char*)str
00093            encoding: (of_string_encoding_t)encoding
00094              length: (size_t)len;
00095 
00104 + stringWithCString: (const char*)str
00105              length: (size_t)len;
00106 
00114 + stringWithFormat: (OFString*)fmt, ...;
00115 
00122 + stringWithPath: (OFString*)first, ...;
00123 
00130 + stringWithString: (OFString*)str;
00131 
00138 + stringWithContentsOfFile: (OFString*)path;
00139 
00148 + stringWithContentsOfFile: (OFString*)path
00149                   encoding: (of_string_encoding_t)encoding;
00150 
00158 + stringWithContentsOfURL: (OFURL*)url;
00159 
00168 + stringWithContentsOfURL: (OFURL*)url
00169                  encoding: (of_string_encoding_t)encoding;
00170 
00177 - initWithCString: (const char*)str;
00178 
00187 - initWithCString: (const char*)str
00188          encoding: (of_string_encoding_t)encoding;
00189 
00199 - initWithCString: (const char*)str
00200          encoding: (of_string_encoding_t)encoding
00201            length: (size_t)len;
00202 
00211 - initWithCString: (const char*)str
00212            length: (size_t)len;
00213 
00221 - initWithFormat: (OFString*)fmt, ...;
00222 
00231 - initWithFormat: (OFString*)fmt
00232        arguments: (va_list)args;
00233 
00241 - initWithPath: (OFString*)first, ...;
00242 
00251 - initWithPath: (OFString*)first
00252      arguments: (va_list)args;
00253 
00260 - initWithString: (OFString*)str;
00261 
00269 - initWithContentsOfFile: (OFString*)path;
00270 
00279 - initWithContentsOfFile: (OFString*)path
00280                 encoding: (of_string_encoding_t)encoding;
00281 
00289 - initWithContentsOfURL: (OFURL*)url;
00290 
00299 - initWithContentsOfURL: (OFURL*)url
00300                encoding: (of_string_encoding_t)encoding;
00301 
00305 - (const char*)cString;
00306 
00310 - (size_t)length;
00311 
00315 - (size_t)cStringLength;
00316 
00318 - (BOOL)isUTF8;
00320 
00327 - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)str;
00328 
00333 - (of_unichar_t)characterAtIndex: (size_t)index;
00334 
00340 - (size_t)indexOfFirstOccurrenceOfString: (OFString*)str;
00341 
00347 - (size_t)indexOfLastOccurrenceOfString: (OFString*)str;
00348 
00353 - (BOOL)containsString: (OFString*)str;
00354 
00361 - (OFString*)substringFromIndex: (size_t)start
00362                         toIndex: (size_t)end;
00363 
00368 - (OFString*)substringWithRange: (of_range_t)range;
00369 
00376 - (OFString*)stringByAppendingString: (OFString*)str;
00377 
00383 - (OFString*)stringByDeletingLeadingWhitespaces;
00384 
00390 - (OFString*)stringByDeletingTrailingWhitespaces;
00391 
00398 - (OFString*)stringByDeletingLeadingAndTrailingWhitespaces;
00399 
00406 - (BOOL)hasPrefix: (OFString*)prefix;
00407 
00414 - (BOOL)hasSuffix: (OFString*)suffix;
00415 
00422 - (OFArray*)componentsSeparatedByString: (OFString*)delimiter;
00423 
00427 - (OFArray*)pathComponents;
00428 
00432 - (OFString*)lastPathComponent;
00433 
00437 - (OFString*)stringByDeletingLastPathComponent;
00438 
00449 - (intmax_t)decimalValue;
00450 
00461 - (uintmax_t)hexadecimalValue;
00462 
00469 - (float)floatValue;
00470 
00477 - (double)doubleValue;
00478 
00486 - (of_unichar_t*)unicodeString;
00487 
00493 - (void)writeToFile: (OFString*)path;
00494 @end
00495 
00496 #import "OFConstantString.h"
00497 #import "OFMutableString.h"
00498 #import "OFString+Hashing.h"
00499 #import "OFString+URLEncoding.h"
00500 #import "OFString+XMLEscaping.h"
00501 #import "OFString+XMLUnescaping.h"
 All Classes Functions Variables