Overview
Comment: | OFString uses OFObject's getMem: and resizeMem:toSize: now. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
0256ab4f0931fec5cea25356ffb535c7 |
User & Date: | js on 2008-09-12 18:21:50 |
Other Links: | manifest | tags |
Context
2008-09-12
| ||
18:26 | Add OFConstString. check-in: a566e7bb03 user: js tags: trunk | |
18:21 | OFString uses OFObject's getMem: and resizeMem:toSize: now. check-in: 0256ab4f09 user: js tags: trunk | |
17:56 | Fix printf, add missing files. check-in: 958016704c user: js tags: trunk | |
Changes
Modified src/OFString.h from [ceca91fa6c] to [9ae2f04448].
︙ | ︙ | |||
17 18 19 20 21 22 23 | char *string; size_t length; } + new:(const char*)str; - init; - init:(const char*)str; | < | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | char *string; size_t length; } + new:(const char*)str; - init; - init:(const char*)str; - (char*)cString; - (size_t)length; - (OFString*)setTo:(const char*)str; - (OFString*)clone; - (OFString*)append:(const char*)str; @end /* vim: se syn=objc: */ |
Modified src/OFString.m from [53999e7524] to [c26b0e5b15].
︙ | ︙ | |||
26 27 28 29 30 31 32 | return [self init:NULL]; } - init:(const char*)str { if ((self = [super init])) { if (str == NULL) { | < > < > > > < < < < < < < | > > > > > > > > > > > > > > > > > | > | | > | | | < < | > | | > > | 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | return [self init:NULL]; } - init:(const char*)str { if ((self = [super init])) { if (str == NULL) { length = 0; string = NULL; } else { length = strlen(string); if ((string = [self getMem:length]) == NULL) return NULL; memcpy(string, str, length); } } return self; } - (char*)cString { return string; } - (size_t)length { return length; } - (OFString*)setTo:(const char*)str { char *newstr; size_t newlen; if (str == NULL) { [self freeMem:string]; length = 0; string = NULL; return self; } newlen = strlen(str); if ((newstr = [self getMem:newlen]) == NULL) return nil; memcpy(newstr, str, newlen); if (string != NULL) [self freeMem:string]; length = newlen; string = newstr; return self; } - (OFString*)clone { if (string != NULL) return [OFString new:string]; return [OFString new]; } - (OFString*)append: (const char*)str { char *new_string; size_t new_length, str_length; if (str == NULL) return [self setTo:str]; str_length = strlen(str); new_length = length + str_length; if ((new_string = [self resizeMem:string toSize:new_length + 1]) == NULL) { /* FIXME: Add error handling */ return nil; } string = new_string; memcpy(string + length, str, str_length); string[new_length] = '\0'; length = new_length; return self; } @end |