Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Coding style. |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
778be56179b4a6716b7d248ed100fc63 |
| User & Date: | js 2008-09-14 15:29:34.000 |
Context
|
2008-09-14
| ||
| 16:43 | Lots of changes. See full commit message. check-in: 7b8b7cd06c user: js tags: trunk | |
| 15:29 | Coding style. check-in: 778be56179 user: js tags: trunk | |
| 15:12 | Fix a bug in OFWideString and add test for OFWideString. check-in: b4ead4bdd2 user: js tags: trunk | |
Changes
Changes to src/OFConstString.h.
| ︙ | ︙ | |||
10 11 12 13 14 15 16 |
*/
#import <stddef.h>
#import "OFObject.h"
@interface OFConstString: OFObject
{
| | | | | < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
*/
#import <stddef.h>
#import "OFObject.h"
@interface OFConstString: OFObject
{
const char *string;
size_t length;
}
+ new: (const char*)str;
- init;
- init: (const char*)str;
- (const char*)cString;
- (size_t)length;
@end
|
Changes to src/OFConstString.m.
| ︙ | ︙ | |||
9 10 11 12 13 14 15 | * the packaging of this file. */ #import <string.h> #import "OFConstString.h" @implementation OFConstString | | | | | | 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 |
* the packaging of this file.
*/
#import <string.h>
#import "OFConstString.h"
@implementation OFConstString
+ new: (const char*)str
{
return [[OFConstString alloc] init: str];
}
- init
{
return [self init: NULL];
}
- init: (const char*)str
{
if ((self = [super init])) {
if (str == NULL) {
length = 0;
string = NULL;
} else {
length = strlen(str);
|
| ︙ | ︙ |
Changes to src/OFConstWideString.h.
| ︙ | ︙ | |||
11 12 13 14 15 16 17 |
#import <stddef.h>
#import <wchar.h>
#import "OFObject.h"
@interface OFConstWideString: OFObject
{
| | | | | < < | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#import <stddef.h>
#import <wchar.h>
#import "OFObject.h"
@interface OFConstWideString: OFObject
{
const wchar_t *wstring;
size_t length;
}
+ new: (const wchar_t*)wstr;
- init;
- init: (const wchar_t*)wstr;
- (const wchar_t*)wcString;
- (size_t)length;
@end
|
Changes to src/OFConstWideString.m.
| ︙ | ︙ | |||
9 10 11 12 13 14 15 | * the packaging of this file. */ #import <wchar.h> #import "OFConstWideString.h" @implementation OFConstWideString | | | | | | 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 |
* the packaging of this file.
*/
#import <wchar.h>
#import "OFConstWideString.h"
@implementation OFConstWideString
+ new: (const wchar_t*)wstr
{
return [[OFConstWideString alloc] init: wstr];
}
- init
{
return [self init: NULL];
}
- init: (const wchar_t*)wstr
{
if ((self = [super init])) {
if (wstr == NULL) {
length = 0;
wstring = NULL;
} else {
length = wcslen(wstr);
|
| ︙ | ︙ |
Changes to src/OFList.h.
| ︙ | ︙ | |||
10 11 12 13 14 15 16 |
*/
#import "OFObject.h"
#import "OFListObject.h"
@interface OFList: OFObject
{
| | | | | < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
*/
#import "OFObject.h"
#import "OFListObject.h"
@interface OFList: OFObject
{
OFListObject *first;
OFListObject *last;
}
- init;
- free;
- freeWithData;
- (OFListObject*)first;
- (OFListObject*)last;
- (void)add: (OFListObject*)ptr;
- (void)addNew: (void*)ptr;
@end
|
Changes to src/OFList.m.
| ︙ | ︙ | |||
52 53 54 55 56 57 58 |
}
- (OFListObject*)last
{
return last;
}
| | | | | | | 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 |
}
- (OFListObject*)last
{
return last;
}
- (void)add: (OFListObject*)ptr
{
if (!first || !last) {
first = last = ptr;
return;
}
[ptr setPrev: last];
[last setNext: ptr];
last = ptr;
}
- (void)addNew: (void*)ptr
{
return [self add: [OFListObject new: ptr]];
}
@end
|
Changes to src/OFListObject.h.
| ︙ | ︙ | |||
9 10 11 12 13 14 15 |
* the packaging of this file.
*/
#import "OFObject.h"
@interface OFListObject: OFObject
{
| | | | | | | | < < | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
* the packaging of this file.
*/
#import "OFObject.h"
@interface OFListObject: OFObject
{
void *data;
OFListObject *next;
OFListObject *prev;
}
+ new: (void*)ptr;
- init: (void*)ptr;
- freeWithData;
- (void*)data;
- (OFListObject*)next;
- (OFListObject*)prev;
- (void)setNext: (OFListObject*)ptr;
- (void)setPrev: (OFListObject*)ptr;
@end
|
Changes to src/OFListObject.m.
| ︙ | ︙ | |||
9 10 11 12 13 14 15 | * the packaging of this file. */ #import <stdlib.h> #import "OFListObject.h" @implementation OFListObject | | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
* the packaging of this file.
*/
#import <stdlib.h>
#import "OFListObject.h"
@implementation OFListObject
+ new: (void*)ptr
{
return [[OFListObject alloc] init: ptr];
}
- init: (void*)ptr
{
if ((self = [super init])) {
next = nil;
prev = nil;
data = ptr;
}
return self;
|
| ︙ | ︙ | |||
46 47 48 49 50 51 52 |
}
- (OFListObject*)prev
{
return prev;
}
| | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
}
- (OFListObject*)prev
{
return prev;
}
- (void)setNext: (OFListObject*)ptr
{
next = ptr;
}
- (void)setPrev: (OFListObject*)ptr
{
prev = ptr;
}
@end
|
Changes to src/OFObject.h.
| ︙ | ︙ | |||
8 9 10 11 12 13 14 |
* Q Public License 1.0, which can be found in the file LICENSE included in
* the packaging of this file.
*/
#import <objc/Object.h>
struct __ofobject_allocated_mem {
| | | | > | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
* Q Public License 1.0, which can be found in the file LICENSE included in
* the packaging of this file.
*/
#import <objc/Object.h>
struct __ofobject_allocated_mem {
void *ptr;
struct __ofobject_allocated_mem *prev;
struct __ofobject_allocated_mem *next;
};
@interface OFObject: Object
{
struct __ofobject_allocated_mem *__mem_pool;
}
- init;
- (void*)getMem: (size_t)size;
- (void*)resizeMem: (void*)ptr
toSize: (size_t)size;
- (void)freeMem: (void*)ptr;
- free;
@end
|
Changes to src/OFObject.m.
| ︙ | ︙ | |||
18 19 20 21 22 23 24 |
- init
{
if ((self = [super init]) != nil)
__mem_pool = NULL;
return self;
}
| | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
- init
{
if ((self = [super init]) != nil)
__mem_pool = NULL;
return self;
}
- (void*)getMem: (size_t)size
{
struct __ofobject_allocated_mem *iter;
if ((iter = malloc(sizeof(struct __ofobject_allocated_mem))) == NULL)
return NULL;
if ((iter->ptr = malloc(size)) == NULL) {
|
| ︙ | ︙ | |||
41 42 43 44 45 46 47 | __mem_pool->next = iter; __mem_pool = iter; return iter->ptr; } | | > | | | | 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 |
__mem_pool->next = iter;
__mem_pool = iter;
return iter->ptr;
}
- (void*)resizeMem: (void*)ptr
toSize: (size_t)size
{
struct __ofobject_allocated_mem *iter;
for (iter = __mem_pool; iter != NULL; iter = iter->prev) {
if (iter->ptr == ptr) {
if ((ptr = realloc(iter->ptr, size)) == NULL)
return NULL;
iter->ptr = ptr;
return ptr;
}
}
fprintf(stderr, "WARNING: Memory at %p was not allocated as part of "
"object %s!\n-> Memory was not resized!\n", ptr, [self name]);
return NULL;
}
- (void)freeMem: (void*)ptr;
{
struct __ofobject_allocated_mem *iter;
for (iter = __mem_pool; iter != NULL; iter = iter->prev) {
if (iter->ptr == ptr) {
if (iter->prev != NULL)
iter->prev->next = iter->next;
if (iter->next != NULL)
iter->next->prev = iter->prev;
free(iter);
free(ptr);
return;
}
}
fprintf(stderr, "WARNING: Memory at %p was not allocated as part of "
"object %s!\n-> Memory was not free'd!\n", ptr, [self name]);
}
- free
{
struct __ofobject_allocated_mem *iter, *iter2;
for (iter = __mem_pool; iter != NULL; iter = iter2) {
|
| ︙ | ︙ |
Changes to src/OFString.h.
| ︙ | ︙ | |||
10 11 12 13 14 15 16 |
*/
#import <stddef.h>
#import "OFObject.h"
@interface OFString: OFObject
{
| | | | | | | < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
*/
#import <stddef.h>
#import "OFObject.h"
@interface OFString: OFObject
{
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
|
Changes to src/OFString.m.
| ︙ | ︙ | |||
10 11 12 13 14 15 16 | */ #import <stdlib.h> #import <string.h> #import "OFString.h" @implementation OFString | | | | | | | | | | | | | < | > > < | 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 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 |
*/
#import <stdlib.h>
#import <string.h>
#import "OFString.h"
@implementation OFString
+ new: (const char*)str
{
return [[OFString alloc] init: str];
}
- init
{
return [self init: NULL];
}
- init: (const char*)str
{
if ((self = [super init])) {
if (str == NULL) {
length = 0;
string = NULL;
} else {
length = strlen(str);
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
{
return [OFString new: string];
}
- (OFString*)append: (const char*)str
{
char *newstr;
size_t newlen, strlength;
if (str == NULL)
return [self setTo:str];
strlength = strlen(str);
newlen = length + strlength;
/* FIXME: Add error handling */
if ((newstr = [self resizeMem: string
toSize: newlen + 1]) == NULL)
return nil;
string = newstr;
memcpy(string + length, str, strlength);
string[newlen] = '\0';
length = newlen;
return self;
}
@end
|
Changes to src/OFWideString.h.
| ︙ | ︙ | |||
15 16 17 18 19 20 21 |
@interface OFWideString: OFObject
{
wchar_t *wstring;
size_t length;
}
| | | | | < < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
@interface OFWideString: OFObject
{
wchar_t *wstring;
size_t length;
}
+ new: (const wchar_t*)wstr;
- init;
- init: (const wchar_t*)wstr;
- (wchar_t*)wcString;
- (size_t)length;
- (OFWideString*)setTo: (const wchar_t*)wstr;
- (OFWideString*)clone;
- (OFWideString*)append: (const wchar_t*)wstr;
@end
|
Changes to src/OFWideString.m.
| ︙ | ︙ | |||
11 12 13 14 15 16 17 | #import <stdlib.h> #import <string.h> #import <wchar.h> #import "OFWideString.h" @implementation OFWideString | | | | | | | | | | | > | | < < | 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 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 |
#import <stdlib.h>
#import <string.h>
#import <wchar.h>
#import "OFWideString.h"
@implementation OFWideString
+ new: (const wchar_t*)wstr
{
return [[OFWideString alloc] init: wstr];
}
- init
{
return [self init: NULL];
}
- init: (const wchar_t*)wstr
{
if ((self = [super init])) {
if (wstr == NULL) {
length = 0;
wstring = NULL;
} else {
length = wcslen(wstr);
if ((wstring =
[self getMem: length * sizeof(wchar_t)]) == NULL)
return NULL;
memcpy(wstring, wstr, length * sizeof(wchar_t));
}
}
return self;
}
- (wchar_t*)wcString
{
return wstring;
}
- (size_t)length
{
return length;
}
- (OFWideString*)setTo: (const wchar_t*)wstr
{
wchar_t *newstr;
size_t newlen;
if (wstr == NULL) {
[self freeMem:wstring];
length = 0;
wstring = NULL;
return self;
}
newlen = wcslen(wstr);
if ((newstr = [self getMem: newlen * sizeof(wchar_t)]) == NULL)
return nil;
memcpy(newstr, wstr, newlen * sizeof(wchar_t));
if (wstring != NULL)
[self freeMem: wstring];
length = newlen;
wstring = newstr;
return self;
}
- (OFWideString*)clone
{
return [OFWideString new: wstring];
}
- (OFWideString*)append: (const wchar_t*)wstr
{
wchar_t *newstr;
size_t newlen, strlength;
if (wstr == NULL)
return [self setTo: wstr];
strlength = wcslen(wstr);
newlen = length + strlength;
/* FIXME: Add error handling */
if ((newstr = [self resizeMem: wstring
toSize: newlen * sizeof(wchar_t) + 2]) == NULL)
return nil;
wstring = newstr;
memcpy(wstring + length * sizeof(wchar_t), wstr,
strlength * sizeof(wchar_t));
wstring[newlen] = '\0';
length = newlen;
return self;
}
@end
|
Changes to tests/OFList/OFList.m.
| ︙ | ︙ | |||
13 14 15 16 17 18 19 |
#import "OFString.h"
#import "OFList.h"
int
main()
{
| | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#import "OFString.h"
#import "OFList.h"
int
main()
{
OFList *list;
OFListObject *iter;
list = [OFList new];
[list addNew: [OFString new: "First String Object"]];
[list addNew: [OFString new: "Second String Object"]];
[list addNew: [OFString new: "Third String Object"]];
|
| ︙ | ︙ |
Changes to tests/OFString/OFString.m.
| ︙ | ︙ | |||
13 14 15 16 17 18 19 |
#import <string.h>
#import "OFString.h"
int
main()
{
| | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#import <string.h>
#import "OFString.h"
int
main()
{
OFString *s1 = [OFString new: "foo"];
OFString *s2 = [[OFString alloc] init: ""];
OFString *s3;
OFString *s4 = [OFString new];
[s2 append: "bar"];
s3 = [s1 clone];
[s4 setTo: [s2 cString]];
printf("s1 = %s\n", [s1 cString]);
printf("s2 = %s\n", [s2 cString]);
printf("s3 = %s\n", [s3 cString]);
printf("s4 = %s\n", [s4 cString]);
[s1 append: [s2 cString]];
|
| ︙ | ︙ |
Changes to tests/OFWideString/OFWideString.m.
| ︙ | ︙ | |||
13 14 15 16 17 18 19 |
#import <wchar.h>
#import "OFWideString.h"
int
main()
{
| | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#import <wchar.h>
#import "OFWideString.h"
int
main()
{
OFWideString *s1 = [OFWideString new: L"foo"];
OFWideString *s2 = [[OFWideString alloc] init: L""];
OFWideString *s3;
OFWideString *s4 = [OFWideString new];
printf("%p\n", [s2 append: L"bar"]);
s3 = [s1 clone];
[s4 setTo: [s2 wcString]];
wprintf(L"s1 = %S\n", [s1 wcString]);
wprintf(L"s2 = %S\n", [s2 wcString]);
wprintf(L"s3 = %S\n", [s3 wcString]);
wprintf(L"s4 = %S\n", [s4 wcString]);
[s1 append: [s2 wcString]];
|
| ︙ | ︙ |