Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | New string API, string class completely rewritten. One class for all string types now. |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
bf02f0ef25bc5ad1cf2979fecad149b1 |
| User & Date: | js 2008-11-23 06:11:59.000 |
Context
|
2008-11-26
| ||
| 14:40 | Support for wide C strings for OFXMLFactory. check-in: cd99b982ac user: js tags: trunk | |
|
2008-11-23
| ||
| 06:11 | New string API, string class completely rewritten. One class for all string types now. check-in: bf02f0ef25 user: js tags: trunk | |
|
2008-11-19
| ||
| 18:27 | Implement reverse for OF(Wide)CString & rename wcString -> wCString. check-in: cebd6fbbfc user: js tags: trunk | |
Changes
Changes to src/Makefile.
1 2 3 4 5 |
LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX}
LIB_MAJOR = 1
LIB_MINOR = 0
SRCS = OFArray.m \
| < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX}
LIB_MAJOR = 1
LIB_MINOR = 0
SRCS = OFArray.m \
OFExceptions.m \
OFHashes.m \
OFFile.m \
OFList.m \
OFListObject.m \
OFObject.m \
OFString.m \
OFXMLFactory.m
INCLUDES = ${SRCS:.m=.h} \
OFMacros.h
include ../buildsys.mk
|
| ︙ | ︙ |
Deleted src/OFCString.h.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFCString.m.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFConstCString.h.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFConstCString.m.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFConstWideCString.h.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFConstWideCString.m.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to src/OFExceptions.h.
| ︙ | ︙ | |||
88 89 90 91 92 93 94 | /** * \return The size of the memoory that couldn't be allocated */ - (size_t)requestedSize; @end | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
/**
* \return The size of the memoory that couldn't be allocated
*/
- (size_t)requestedSize;
@end
/**
* An OFException indicating the given memory is not part of the object.
*/
@interface OFMemNotPartOfObjException: OFException
{
void *pointer;
}
|
| ︙ | ︙ |
Changes to src/OFExceptions.m.
| ︙ | ︙ | |||
92 93 94 95 96 97 98 |
return string;
}
- (size_t)requestedSize
{
return req_size;
}
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
return string;
}
- (size_t)requestedSize
{
return req_size;
}
@end
@implementation OFMemNotPartOfObjException
+ newWithObject: (id)obj
andPointer: (void*)ptr
{
return [[OFMemNotPartOfObjException alloc] initWithObject: obj
|
| ︙ | ︙ |
Changes to src/OFMacros.h.
1 2 3 4 5 6 7 8 9 10 11 | /* * 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. */ | < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/*
* 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.
*/
#ifdef OF_BIG_ENDIAN
static inline void
OF_BSWAP_V(uint8_t *buf, size_t len)
{
uint32_t t;
while (len--) {
|
| ︙ | ︙ |
Changes to src/OFString.h.
| ︙ | ︙ | |||
11 12 13 14 15 16 17 | #import <wchar.h> #import <stddef.h> #import "OFObject.h" /** | | | > > > > > > > > > > | > | > > | | > > | < | | > > > > > > > > > | | | > > | | | | > | | < < < < < < < > > > > > > > > | | | | | 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 115 116 117 118 119 120 121 |
#import <wchar.h>
#import <stddef.h>
#import "OFObject.h"
/**
* A class for storing and modifying strings.
*/
@interface OFString: OFObject
{
wchar_t *string;
size_t length;
}
/**
* Creates a new OFString.
*
* \return An initialized OFString
*/
+ new;
/**
* Creates a new OFString from a C string.
*
* \param str A C string to initialize the OFString with
* \return A new OFString
*/
+ newFromCString: (const char*)str;
/**
* Creates a new OFString from a wide C string.
*
* \param str A wide C string to initialize the OFString with
* \return A new OFString
*/
+ newFromWideCString: (const wchar_t*)str;
/**
* Initializes an already allocated OFString.
*
* \return An initialized OFString
*/
- init;
/**
* Initializes an already allocated OFString from a C string.
*
* \param str A C string to initialize the OFString with
* \return An initialized OFString
*/
- initFromCString: (const char*)str;
/**
* Initializes an already allocated OFString from a wide C string.
*
* \param str A wide C string to initialize the OFString with
* \return An initialized OFString
*/
- initFromWideCString: (const wchar_t*)str;
/**
* \return The OFString as a C string, if possible (if not, returns NULL).
* If not needed anymore, it is usefull to call freeMem:.
*/
- (char*)cString;
/**
* \return The OFString as a wide C string
*/
- (wchar_t*)wideCString;
/**
* \return The length of the OFString
*/
- (size_t)length;
/**
* Clones the OFString, creating a new one.
*
* \return A copy of the OFString
*/
- (OFString*)clone;
/**
* Frees the OFString and sets it to the specified OFString.
*
* \param str An OFString to set the OFString to.
* \return The new OFString
*/
- (OFString*)setTo: (OFString*)str;
/**
* Compares the OFString to another OFString.
*
* \param str An OFString to compare with
* \return An integer which is the result of the comparison, see wcscmp
*/
- (int)compare: (OFString*)str;
/**
* Append another OFString to the OFString.
*
* \param str An OFString to append
*/
- append: (OFString*)str;
/**
* Append a C string to the OFString.
*
* \param str A C string to append
|
| ︙ | ︙ |
Changes to src/OFString.m.
| ︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 | * the packaging of this file. */ #import "config.h" #import <stdlib.h> #import <string.h> #import "OFString.h" | > < < < < < > > > > > | | | > > | > > > > > | > > > | > > > > > > > > | | > > > > > > > > > > > > > | > > > > > > > > > > > | > > > | > > > | > > > > > > > > > > > | < > > > | > > > | < | < < | < < < | > > | > > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > | > > > > > > > | 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 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 |
* the packaging of this file.
*/
#import "config.h"
#import <stdlib.h>
#import <string.h>
#import <wchar.h>
#import "OFString.h"
#import "OFExceptions.h"
@implementation OFString
+ new
{
return [[OFString alloc] init];
}
+ newFromCString: (const char*)str
{
return [[OFString alloc] initFromCString: str];
}
+ newFromWideCString: (const wchar_t*)str
{
return [[OFString alloc] initFromWideCString: str];
}
- init
{
if ((self = [super init])) {
length = 0;
string = NULL;
}
return self;
}
- initFromCString: (const char*)str
{
if ((self = [super init])) {
if (str == NULL) {
length = 0;
string = NULL;
} else {
if ((length = mbstowcs(NULL, str, 0)) == (size_t)-1) {
/* FIXME: Throw exception */
[super free];
return nil;
}
string = [self getMemForNItems: length + 1
ofSize: sizeof(wchar_t)];
if (mbstowcs(string, str, length) != length) {
[super free];
return nil;
}
}
}
return self;
}
- initFromWideCString: (const wchar_t*)str
{
if ((self = [super init])) {
if (str == NULL) {
length = 0;
string = NULL;
} else {
length = wcslen(str);
string = [self getMemForNItems: length + 1
ofSize: sizeof(wchar_t)];
wmemcpy(string, str, length + 1);
}
}
return self;
}
- (char*)cString
{
char *str;
size_t len;
if ((len = wcstombs(NULL, string, 0)) == (size_t)-1) {
/* FIXME: Throw exception */
return NULL;
}
str = [self getMemWithSize: len];
if (wcstombs(str, string, len) != len) {
/* FIXME: Throw exception */
[self freeMem: str];
return NULL;
}
return str;
}
- (wchar_t*)wideCString
{
return string;
}
- (size_t)length
{
return length;
}
- (OFString*)clone
{
return [OFString newFromWideCString: string];
}
- (OFString*)setTo: (OFString*)str
{
[self free];
return (self = [str clone]);
}
- (int)compare: (OFString*)str
{
return wcscmp(string, [str wideCString]);
}
- append: (OFString*)str
{
return [self appendWideCString: [str wideCString]];
}
- appendCString: (const char*)str
{
wchar_t *newstr, *tmpstr;
size_t newlen, strlength;
if (string == NULL)
return [self setTo: [OFString newFromCString: str]];
if ((strlength = mbstowcs(NULL, str, 0)) == (size_t)-1) {
/* FIXME: Throw exception */
return nil;
}
tmpstr = [self getMemForNItems: strlength + 1
ofSize: sizeof(wchar_t)];
if (mbstowcs(tmpstr, str, strlength) != strlength) {
/* FIXME: Throw exception */
[self freeMem: tmpstr];
return nil;
}
newlen = length + strlength;
newstr = [self resizeMem: string
toNItems: newlen + 1
ofSize: sizeof(wchar_t)];
wmemcpy(newstr + length, tmpstr, strlength + 1);
length = newlen;
string = newstr;
[self freeMem: tmpstr];
return self;
}
- appendWideCString: (const wchar_t*)str
{
wchar_t *newstr;
size_t newlen, strlength;
if (string == NULL)
return [self setTo: [OFString newFromWideCString: str]];
strlength = wcslen(str);
newlen = length + strlength;
newstr = [self resizeMem: string
toNItems: newlen + 1
ofSize: sizeof(wchar_t)];
wmemcpy(newstr + length, str, strlength + 1);
length = newlen;
string = newstr;
return self;
}
- reverse
{
size_t i, j, len = length / 2;
for (i = 0, j = length - 1; i < len; i++, j--) {
string[i] ^= string[j];
string[j] ^= string[i];
string[i] ^= string[j];
}
return self;
}
@end
|
Deleted src/OFWideCString.h.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFWideCString.m.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Changes to tests/Makefile.
|
| | > > > > > | 1 2 3 4 5 6 7 8 | SUBDIRS = OFObject \ OFArray \ OFHashes \ OFString \ OFList \ OFXMLFactory include ../buildsys.mk |
Changes to tests/OFList/OFList.m.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /* * 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 <stdio.h> #import <string.h> #import "OFString.h" #import "OFList.h" /* TODO: Do real checks */ | > | | | | | | | | | | | 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 |
/*
* 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 <stdio.h>
#import <string.h>
#import "OFString.h"
#import "OFList.h"
/* TODO: Do real checks */
const wchar_t *strings[] = {
L"First String Object",
L"Second String Object",
L"Third String Object"
};
int
main()
{
size_t i;
OFList *list;
OFListObject *iter;
list = [OFList new];
[list addNew: [OFString newFromWideCString: strings[0]]];
[list addNew: [OFString newFromWideCString: strings[1]]];
[list addNew: [OFString newFromWideCString: strings[2]]];
for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
if (!wcscmp([(OFString*)[iter data] wideCString], strings[i]))
printf("Element %zu is expected element. GOOD!\n", i);
else {
printf("Element %zu is not expected element!\n", i);
return 1;
}
if (!wcscmp([(OFString*)[[list first] data] wideCString], strings[0]))
puts("First element is expected element. GOOD!");
else {
puts("First element is not expected element!");
return 1;
}
if (!wcscmp([(OFString*)[[list last] data] wideCString], strings[2]))
puts("Last element is expected element. GOOD!");
else {
puts("Last element is not expected element!");
return 1;
}
[list freeIncludingData];
|
| ︙ | ︙ |
Changes to tests/OFString/OFString.m.
| ︙ | ︙ | |||
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 |
#import "OFString.h"
/* TODO: Do real checks */
int
main()
{
OFString *s1 = [OFString newFromCString: "test"];
OFString *s2 = [OFString newFromCString: ""];
OFString *s3;
OFString *s4 = [OFString new];
s3 = [s1 clone];
if (![s1 compare: s3])
puts("s1 and s3 match! GOOD!");
else {
puts("s1 and s3 don't match!");
return 1;
}
[s2 appendCString: "123"];
[s4 setTo: s2];
if (![s2 compare: s4])
puts("s2 and s4 match! GOOD!");
else {
puts("s2 and s4 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!");
|
| ︙ | ︙ |
Deleted tests/OFWideString/Makefile.
|
| < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFWideString/OFWideString.m.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |