ObjFW  Check-in [328decd247]

Overview
Comment:Use +[stringWithCString:andLength:] in -[readLine].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 328decd2470017205af39519a569915d16a160e3db7259ffd89f03d4209dbf07
User & Date: js on 2009-07-17 11:25:49
Other Links: manifest | tags
Context
2009-07-17
12:41
Add OFString (OFHashing) category. check-in: d051b1302d user: js tags: trunk
11:25
Use +[stringWithCString:andLength:] in -[readLine]. check-in: 328decd247 user: js tags: trunk
2009-07-16
23:59
OFConstString: Throw OFNotImplementedException for unavailable methods. check-in: 9bcba32807 user: js tags: trunk
Changes

Modified src/OFStream.m from [b556a211fc] to [fc7e1fba0a].

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
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







-
-
-
+
+

-
-
-
+

-
-
-
-




-
+

-
-
-
-
-
-















-
-
-
-
-
-
+
-
-
-
+







	OFString *ret;

	/* Look if there's a line or \0 in our cache */
	if (cache != NULL) {
		for (i = 0; i < cache_len; i++) {
			if (OF_UNLIKELY(cache[i] == '\n' ||
			    cache[i] == '\0')) {
				ret_c = [self allocMemoryWithSize: i + 1];
				memcpy(ret_c, cache, i);
				ret_c[i] = '\0';
				ret = [OFString stringWithCString: cache
							andLength: i];

				@try {
					tmp = [self
					    allocMemoryWithSize: cache_len -
				tmp = [self allocMemoryWithSize: cache_len -
								 i - 1];
				} @catch (OFException *e) {
					[self freeMemory: ret_c];
					@throw e;
				}
				memcpy(tmp, cache + i + 1, cache_len - i - 1);

				[self freeMemory: cache];
				cache = tmp;
				cache_len = cache_len - i - 1;
				cache_len -= i + 1;

				@try {
					ret = [OFString
					    stringWithCString: ret_c];
				} @finally {
					[self freeMemory: ret_c];
				}
				return ret;
			}
		}
	}

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	for (;;) {
		if ([self atEndOfStream]) {
			[self freeMemory: tmp];

			if (cache == NULL)
				return nil;

			ret_c = [self allocMemoryWithSize: cache_len + 1];
			memcpy(ret_c, cache, cache_len);
			ret_c[cache_len] = '\0';

			@try {
				ret = [OFString stringWithCString: ret_c];
			ret = [OFString stringWithCString: cache
			} @finally {
				[self freeMemory: ret_c];
			}
						andLength: cache_len];

			[self freeMemory: cache];
			cache = NULL;
			cache_len = 0;

			return ret;
		}