Comment: | Reworked String API. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
cf85bee74f29b61b79fcfaa0cec70db1 |
User & Date: | js on 2008-10-05 19:20:33 |
Other Links: | manifest | tags |
2008-10-07
| ||
17:18 | Added OFFile. check-in: 71119a787b user: js tags: trunk | |
2008-10-05
| ||
19:20 | Reworked String API. check-in: cf85bee74f user: js tags: trunk | |
2008-09-15
| ||
11:02 | API change. check-in: c7f702cc69 user: js tags: trunk | |
Modified src/Makefile from [2b071b3432] to [be14b6ad32].
1 2 3 4 | LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX} LIB_MAJOR = 1 LIB_MINOR = 0 | | > | | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX} LIB_MAJOR = 1 LIB_MINOR = 0 SRCS = OFConstCString.m \ OFCString.m \ OFConstWideCString.m \ OFExceptions.m \ OFList.m \ OFListObject.m \ OFObject.m \ OFString.m \ OFWideCString.m INCLUDES = OFConstString.h \ OFCString.h \ OFConstWideString.h \ OFExceptions.h \ OFList.h \ OFListObject.h \ OFObject.h \ OFString.h \ OFWideString.h |
︙ | ︙ |
Added src/OFCString.h version [b9bde22b67].
> > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stddef.h> #import "OFObject.h" #import "OFString.h" @interface OFCString: OFString { char *string; } - initWithCString: (char*)str; - (char*)cString; - (OFString*)clone; - (int)compare: (OFString*)str; - (OFString*)append: (OFString*)str; @end |
Added src/OFCString.m version [b967cecc4b].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 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 64 65 66 67 68 69 70 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stdlib.h> #import <string.h> #import "OFCString.h" #import "OFExceptions.h" @implementation OFCString - initWithCString: (const char*)str { if ((self = [super init])) { if (str == NULL) { length = 0; string = NULL; } else { length = strlen(str); string = [self getMem: length + 1]; memcpy(string, str, length + 1); } } return self; } - (char*)cString { return string; } - (OFString*)clone { return [OFString newWithCString: string]; } - (int)compare: (OFString*)str { return strcmp(string, [str cString]); } - (OFString*)append: (OFString*)str { char *newstr; size_t newlen, strlength; if (str == NULL) return [self setTo: str]; strlength = [str length]; newlen = length + strlength; newstr = [self resizeMem: string toSize: newlen + 1]; memcpy(newstr + length, [str cString], strlength + 1); length = newlen; string = newstr; return self; } @end |
Added src/OFConstCString.h version [d27a028e68].
> > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import "OFString.h" @interface OFConstCString: OFString { const char *string; } - initWithConstCString: (const char*)str; - (const char*)cString; - (OFString*)clone; - (int)compare: (OFString*)str; @end |
Added src/OFConstCString.m version [d6fb406d96].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 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 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <string.h> #import "OFConstCString.h" @implementation OFConstCString - initWithConstCString: (const char*)str { if ((self = [super init])) { if (str == NULL) { length = 0; string = NULL; } else { length = strlen(str); string = str; } } return self; } - (const char*)cString { return string; } - (OFString*)clone { return [OFString newWithConstCString: string]; } - (int)compare: (OFString*)str { return strcmp(string, [str cString]); } @end |
Deleted src/OFConstString.h version [8a959a6c98].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFConstString.m version [59a339f3e5].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added src/OFConstWideCString.h version [357f188ce4].
> > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <wchar.h> #import <stddef.h> #import "OFString.h" @interface OFConstWideCString: OFString { const wchar_t *string; } - initWithConstWideCString: (const wchar_t*)wstr; - (const wchar_t*)wcString; - (OFString*)clone; - (int)compare: (OFString*)str; @end |
Added src/OFConstWideCString.m version [1c21e29078].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 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 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <wchar.h> #import "OFConstWideCString.h" @implementation OFConstWideCString - initWithConstWideCString: (const wchar_t*)str { if ((self = [super init])) { if (str == NULL) { length = 0; string = NULL; } else { length = wcslen(str); string = str; } } return self; } - (const wchar_t*)wcString { return string; } - (OFString*)clone { return [OFString newWithConstWideCString: string]; } - (int)compare: (OFString*)str { return wcscmp(string, [str wcString]); } @end |
Deleted src/OFConstWideString.h version [03dfdece23].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFConstWideString.m version [c0a8ed45c4].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/OFExceptions.h from [03ab1df298] to [da96e169ec].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | @interface OFNoMemException: OFException + new: (id)obj withSize: (size_t)size; - init: (id)obj withSize: (size_t)size; @end @interface OFMemNotPartOfObjException: OFException + new: (id)obj withPtr: (void*)ptr; - init: (id)obj withPtr: (void*)ptr; @end | > > > > > > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | @interface OFNoMemException: OFException + new: (id)obj withSize: (size_t)size; - init: (id)obj withSize: (size_t)size; @end @interface OFNotImplementedException: OFException + new: (id)obj withMethod: (const char*)method; - init: (id)obj withMethod: (const char*)method; @end @interface OFMemNotPartOfObjException: OFException + new: (id)obj withPtr: (void*)ptr; - init: (id)obj withPtr: (void*)ptr; @end |
Modified src/OFExceptions.m from [f7b03ef0d0] to [864964c046].
︙ | ︙ | |||
33 34 35 36 37 38 39 | } - init: (id)obj withSize: (size_t)size { fprintf(stderr, "ERROR: Could not allocate %zu bytes for object %s!\n", size, [obj name]); | > | > > > > > > > > > > > > > > > | 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 | } - init: (id)obj withSize: (size_t)size { fprintf(stderr, "ERROR: Could not allocate %zu bytes for object %s!\n", size, [obj name]); return [super init]; } @end @implementation OFNotImplementedException + new: (id)obj withMethod: (const char*)method { return [[OFNotImplementedException alloc] init: obj withMethod: method]; } - init: (id)obj withMethod: (const char*)method { fprintf(stderr, "ERROR: Requested method %s not implemented in %s!\n", method, [obj name]); return [super init]; } @end @implementation OFMemNotPartOfObjException + new: (id)obj withPtr: (void*)ptr |
︙ | ︙ |
Modified src/OFString.h from [236184ed79] to [9a4ef12426].
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stddef.h> #import "OFObject.h" | > < < | | | > > | > | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <wchar.h> #import <stddef.h> #import "OFObject.h" @interface OFString: OFObject { size_t length; } + newWithConstCString: (const char*)str; + newWithConstWideCString: (const wchar_t*)str; + newWithCString: (char*)str; + newWithWideCString: (wchar_t*)str; - (char*)cString; - (wchar_t*)wcString; - (size_t)length; - (OFString*)setTo: (OFString*)str; - (OFString*)clone; - (int)compare: (OFString*)str; - (OFString*)append: (OFString*)str; @end |
Modified src/OFString.m from [68b2726756] to [3e627dd8f1].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stdlib.h> #import <string.h> #import "OFString.h" #import "OFExceptions.h" @implementation OFString | > > > > > | | < > | | < < < | < < < < | | > > | > | > > > > > > | < < < < | < < < < < < < | < < < < < < < < < > | | < < | < | | < < < < | < | < < | | < < < < < | 1 2 3 4 5 6 7 8 9 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stdlib.h> #import <string.h> #import "OFString.h" #import "OFConstCString.h" #import "OFConstWideCString.h" #import "OFCString.h" #import "OFWideCString.h" #import "OFExceptions.h" @implementation OFString + newWithConstCString: (const char*)str { return [[OFConstCString alloc] initWithConstCString: str]; } + newWithConstWideCString: (const wchar_t*)str { return [[OFConstWideCString alloc] initWithConstWideCString: str]; } + newWithCString: (char*)str { return [[OFCString alloc] initWithCString: str]; } + newWithWideCString: (wchar_t*)str { return [[OFWideCString alloc] initWithWideCString: str]; } - (char*)cString { @throw [OFNotImplementedException new: self withMethod: "cString"]; return NULL; } - (wchar_t*)wcString { @throw [OFNotImplementedException new: self withMethod: "wcString"]; return NULL; } - (size_t)length { return length; } - (OFString*)setTo: (OFString*)str { [self free]; self = [str clone]; return self; } - (OFString*)clone { @throw [OFNotImplementedException new: self withMethod: "clone"]; return nil; } - (int)compare: (OFString*)str { @throw [OFNotImplementedException new: self withMethod: "compare:"]; return 0; } - (OFString*)append: (OFString*)str { @throw [OFNotImplementedException new: self withMethod: "append:"]; return nil; } @end |
Added src/OFWideCString.h version [80e2b819bc].
> > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <wchar.h> #import <stddef.h> #import "OFString.h" @interface OFWideCString: OFString { wchar_t *string; } - initWithWideCString: (wchar_t*)str; - (wchar_t*)wcString; - (OFString*)clone; - (int)compare: (OFString*)str; - (OFString*)append: (OFString*)str; @end |
Added src/OFWideCString.m version [87572356ea].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 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 64 65 66 67 68 69 70 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <stdlib.h> #import <string.h> #import <wchar.h> #import "OFWideCString.h" #import "OFExceptions.h" @implementation OFWideCString - initWithWideCString: (wchar_t*)str { if ((self = [super init])) { if (str == NULL) { length = 0; string = NULL; } else { length = wcslen(str); string = [self getMem: (length + 1) * sizeof(wchar_t)]; wmemcpy(string, str, length + 1); } } return self; } - (wchar_t*)wcString { return string; } - (OFString*)clone { return [OFString newWithWideCString: string]; } - (int)compare: (OFString*)str { return wcscmp(string, [str wcString]); } - (OFString*)append: (OFString*)str { wchar_t *newstr; size_t newlen, strlength; if ([str wcString] == NULL) return [self setTo: str]; strlength = [str length]; newlen = length + strlength; newstr = [self resizeMem: string toSize: (newlen + 1) * sizeof(wchar_t)]; wmemcpy(newstr + length, [str wcString], strlength + 1); length = newlen; string = newstr; return self; } @end |
Deleted src/OFWideString.h version [fa40106b5c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFWideString.m version [ffeec9ddfb].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified tests/OFList/OFList.m from [bc3bf85f04] to [27298bf4ec].
︙ | ︙ | |||
28 29 30 31 32 33 34 | { size_t i; OFList *list; OFListObject *iter; list = [OFList new]; | | | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | { size_t i; OFList *list; OFListObject *iter; list = [OFList new]; [list addNew: [OFString newWithConstCString: strings[0]]]; [list addNew: [OFString newWithConstCString: strings[1]]]; [list addNew: [OFString newWithConstCString: strings[2]]]; for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++) if (!strcmp([(OFString*)[iter data] cString], strings[i])) printf("Element %zu is expected element. GOOD!\n", i); else { printf("Element %zu is not expected element!\n", i); return 1; |
︙ | ︙ |
Modified tests/OFString/OFString.m from [d5b6a278de] to [453b60b8cb].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFString.h" /* TODO: Do real checks */ int main() { | | | | | | | | | | 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 | #import "OFString.h" /* TODO: Do real checks */ int main() { OFString *s1 = [OFString newWithCString: "test"]; OFString *s2 = [OFString newWithCString: ""]; OFString *s3; OFString *s4 = [OFString newWithConstCString: NULL]; [s2 append: [OFString newWithConstCString: "123"]]; s3 = [s1 clone]; [s4 setTo: s2]; if (![s1 compare: s3]) puts("s1 and s3 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } if (![s2 compare: s4]) puts("s2 and s4 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } if (!strcmp([[s1 append: s2] cString], "test123")) puts("s1 appended with s2 is the expected string! GOOD!"); else { puts("s1 appended with s2 is not the expected string!"); return 1; } if (strlen([s1 cString]) == [s1 length] && [s1 length] == 7) |
︙ | ︙ |
Modified tests/OFWideString/OFWideString.m from [890eff7e87] to [181ff63706].
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <wchar.h> | | | | | | | | | | | | 1 2 3 4 5 6 7 8 9 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 | /* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import <wchar.h> #import "OFString.h" /* TODO: Do real checks */ int main() { OFString *s1 = [OFString newWithWideCString: L"test"]; OFString *s2 = [OFString newWithWideCString: L""]; OFString *s3; OFString *s4 = [OFString newWithConstWideCString: NULL]; [s2 append: [OFString newWithConstWideCString: L"123"]]; s3 = [s1 clone]; [s4 setTo: s2]; if (![s1 compare: s3]) puts("s1 and s3 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } if (![s2 compare: s4]) puts("s2 and s4 match! GOOD!"); else { puts("s1 and s3 don't match!"); return 1; } if (!wcscmp([[s1 append: s2] wcString], L"test123")) puts("s1 appended with s2 is the expected string! GOOD!"); else { puts("s1 appended with s2 is not the expected string!"); return 1; } if (wcslen([s1 wcString]) == [s1 length] && [s1 length] == 7) |
︙ | ︙ |