ObjFW  Check-in [00dbb47969]

Overview
Comment:Clean up the path delimiter mess.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 00dbb47969c4a969ab1434a24a3aeea04062ff0848062b99122fe0d78177874d
User & Date: js on 2013-12-01 11:50:57
Other Links: manifest | tags
Context
2013-12-01
11:51
OFException: Do not show <??+offset>. check-in: 353b3ba81d user: js tags: trunk
11:50
Clean up the path delimiter mess. check-in: 00dbb47969 user: js tags: trunk
02:08
Port to DOS/DJGPP. check-in: a0b63a8df4 user: js tags: trunk
Changes

Modified src/OFString.m from [95256ec388] to [0e48ad1696].

1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
	if (length == 0)
		return ret;

	pool = objc_autoreleasePoolPush();

	characters = [self characters];

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (characters[length - 1] == OF_PATH_DELIMITER)
#else
	if (characters[length - 1] == '/' || characters[length - 1] == '\\')
#endif
		length--;

	for (i = 0; i < length; i++) {
#if !defined(_WIN32) && !defined(__DJGPP__)
		if (characters[i] == OF_PATH_DELIMITER) {
#else
		if (characters[i] == '/' || characters[i] == '\\') {
#endif
			[ret addObject: [self substringWithRange:
			    of_range(last, i - last)]];

			last = i + 1;
		}
	}








<
|
<
<
<



<
|
<
<
<







1973
1974
1975
1976
1977
1978
1979

1980



1981
1982
1983

1984



1985
1986
1987
1988
1989
1990
1991
	if (length == 0)
		return ret;

	pool = objc_autoreleasePoolPush();

	characters = [self characters];


	if (OF_IS_PATH_DELIMITER(characters[length - 1]))



		length--;

	for (i = 0; i < length; i++) {

		if (OF_IS_PATH_DELIMITER(characters[i])) {



			[ret addObject: [self substringWithRange:
			    of_range(last, i - last)]];

			last = i + 1;
		}
	}

2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
	if (length == 0)
		return @"";

	pool = objc_autoreleasePoolPush();

	characters = [self characters];

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (characters[length - 1] == OF_PATH_DELIMITER)
#else
	if (characters[length - 1] == '/' || characters[length - 1] == '\\')
#endif
		length--;

	for (i = length - 1; i >= 0; i--) {
#if !defined(_WIN32) && !defined(__DJGPP__)
		if (characters[i] == OF_PATH_DELIMITER) {
#else
		if (characters[i] == '/' || characters[i] == '\\') {
#endif
			i++;
			break;
		}
	}

	objc_autoreleasePoolPop(pool);








<
|
<
<
<



<
|
<
<
<







2008
2009
2010
2011
2012
2013
2014

2015



2016
2017
2018

2019



2020
2021
2022
2023
2024
2025
2026
	if (length == 0)
		return @"";

	pool = objc_autoreleasePoolPush();

	characters = [self characters];


	if (OF_IS_PATH_DELIMITER(characters[length - 1]))



		length--;

	for (i = length - 1; i >= 0; i--) {

		if (OF_IS_PATH_DELIMITER(characters[i])) {



			i++;
			break;
		}
	}

	objc_autoreleasePoolPop(pool);

2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
	if (length == 0)
		return @"";

	pool = objc_autoreleasePoolPush();

	characters = [self characters];

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (characters[length - 1] == OF_PATH_DELIMITER)
#else
	if (characters[length - 1] == '/' || characters[length - 1] == '\\')
#endif
		length--;

	if (length == 0) {
		objc_autoreleasePoolPop(pool);
		return [self substringWithRange: of_range(0, 1)];
	}

	for (i = length - 1; i >= 1; i--) {
#if !defined(_WIN32) && !defined(__DJGPP__)
		if (characters[i] == OF_PATH_DELIMITER) {
#else
		if (characters[i] == '/' || characters[i] == '\\') {
#endif
			objc_autoreleasePoolPop(pool);
			return [self substringWithRange: of_range(0, i)];
		}
	}

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (characters[0] == OF_PATH_DELIMITER) {
#else
	if (characters[0] == '/' || characters[0] == '\\') {
#endif
		objc_autoreleasePoolPop(pool);
		return [self substringWithRange: of_range(0, 1)];
	}

	objc_autoreleasePoolPop(pool);

	return OF_PATH_CURRENT_DIRECTORY;







<
|
<
<
<








<
|
<
<
<





<
|
<
<
<







2063
2064
2065
2066
2067
2068
2069

2070



2071
2072
2073
2074
2075
2076
2077
2078

2079



2080
2081
2082
2083
2084

2085



2086
2087
2088
2089
2090
2091
2092
	if (length == 0)
		return @"";

	pool = objc_autoreleasePoolPush();

	characters = [self characters];


	if (OF_IS_PATH_DELIMITER(characters[length - 1]))



		length--;

	if (length == 0) {
		objc_autoreleasePoolPop(pool);
		return [self substringWithRange: of_range(0, 1)];
	}

	for (i = length - 1; i >= 1; i--) {

		if (OF_IS_PATH_DELIMITER(characters[i])) {



			objc_autoreleasePoolPop(pool);
			return [self substringWithRange: of_range(0, i)];
		}
	}


	if (OF_IS_PATH_DELIMITER(characters[0])) {



		objc_autoreleasePoolPop(pool);
		return [self substringWithRange: of_range(0, 1)];
	}

	objc_autoreleasePoolPop(pool);

	return OF_PATH_CURRENT_DIRECTORY;

Modified src/OFString_UTF8.m from [458af69b3f] to [cb1d0ad5b1].

1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
	ret = [OFMutableArray array];

	if (pathCStringLength == 0)
		return ret;

	pool = objc_autoreleasePoolPush();

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (_s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER)
#else
	if (_s->cString[pathCStringLength - 1] == '/' ||
	    _s->cString[pathCStringLength - 1] == '\\')
#endif
		pathCStringLength--;

	for (i = 0; i < pathCStringLength; i++) {
#if !defined(_WIN32) && !defined(__DJGPP__)
		if (_s->cString[i] == OF_PATH_DELIMITER) {
#else
		if (_s->cString[i] == '/' || _s->cString[i] == '\\') {
#endif
			[ret addObject:
			    [OFString stringWithUTF8String: _s->cString + last
						    length: i - last]];
			last = i + 1;
		}
	}








<
<
<
<
|
<



<
|
<
<
<







1092
1093
1094
1095
1096
1097
1098




1099

1100
1101
1102

1103



1104
1105
1106
1107
1108
1109
1110
	ret = [OFMutableArray array];

	if (pathCStringLength == 0)
		return ret;

	pool = objc_autoreleasePoolPush();





	if (OF_IS_PATH_DELIMITER(_s->cString[pathCStringLength - 1]))

		pathCStringLength--;

	for (i = 0; i < pathCStringLength; i++) {

		if (OF_IS_PATH_DELIMITER(_s->cString[i])) {



			[ret addObject:
			    [OFString stringWithUTF8String: _s->cString + last
						    length: i - last]];
			last = i + 1;
		}
	}

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
{
	size_t pathCStringLength = _s->cStringLength;
	ssize_t i;

	if (pathCStringLength == 0)
		return @"";

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (_s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER)
#else
	if (_s->cString[pathCStringLength - 1] == '/' ||
	    _s->cString[pathCStringLength - 1] == '\\')
#endif
		pathCStringLength--;

	for (i = pathCStringLength - 1; i >= 0; i--) {
#if !defined(_WIN32) && !defined(__DJGPP__)
		if (_s->cString[i] == OF_PATH_DELIMITER) {
#else
		if (_s->cString[i] == '/' || _s->cString[i] == '\\') {
#endif
			i++;
			break;
		}
	}

	/*
	 * Only one component, but the trailing delimiter might have been







<
<
<
<
|
<



<
|
<
<
<







1122
1123
1124
1125
1126
1127
1128




1129

1130
1131
1132

1133



1134
1135
1136
1137
1138
1139
1140
{
	size_t pathCStringLength = _s->cStringLength;
	ssize_t i;

	if (pathCStringLength == 0)
		return @"";





	if (OF_IS_PATH_DELIMITER(_s->cString[pathCStringLength - 1]))

		pathCStringLength--;

	for (i = pathCStringLength - 1; i >= 0; i--) {

		if (OF_IS_PATH_DELIMITER(_s->cString[i])) {



			i++;
			break;
		}
	}

	/*
	 * Only one component, but the trailing delimiter might have been
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
- (OFString*)stringByDeletingLastPathComponent
{
	size_t i, pathCStringLength = _s->cStringLength;

	if (pathCStringLength == 0)
		return @"";

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (_s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER)
#else
	if (_s->cString[pathCStringLength - 1] == '/' ||
	    _s->cString[pathCStringLength - 1] == '\\')
#endif
		pathCStringLength--;

	if (pathCStringLength == 0)
		return [OFString stringWithUTF8String: _s->cString
					       length: 1];

	for (i = pathCStringLength - 1; i >= 1; i--)
#if !defined(_WIN32) && !defined(__DJGPP__)
		if (_s->cString[i] == OF_PATH_DELIMITER)
#else
		if (_s->cString[i] == '/' || _s->cString[i] == '\\')
#endif
			return [OFString stringWithUTF8String: _s->cString
						       length: i];

#if !defined(_WIN32) && !defined(__DJGPP__)
	if (_s->cString[0] == OF_PATH_DELIMITER)
#else
	if (_s->cString[0] == '/' || _s->cString[0] == '\\')
#endif
		return [OFString stringWithUTF8String: _s->cString
					       length: 1];

	return @".";
}

- (const of_unichar_t*)characters







<
<
<
<
|
<







<
|
<
<
<



<
|
<
<
<







1150
1151
1152
1153
1154
1155
1156




1157

1158
1159
1160
1161
1162
1163
1164

1165



1166
1167
1168

1169



1170
1171
1172
1173
1174
1175
1176
- (OFString*)stringByDeletingLastPathComponent
{
	size_t i, pathCStringLength = _s->cStringLength;

	if (pathCStringLength == 0)
		return @"";





	if (OF_IS_PATH_DELIMITER(_s->cString[pathCStringLength - 1]))

		pathCStringLength--;

	if (pathCStringLength == 0)
		return [OFString stringWithUTF8String: _s->cString
					       length: 1];

	for (i = pathCStringLength - 1; i >= 1; i--)

		if (OF_IS_PATH_DELIMITER(_s->cString[i]))



			return [OFString stringWithUTF8String: _s->cString
						       length: i];


	if (OF_IS_PATH_DELIMITER(_s->cString[0]))



		return [OFString stringWithUTF8String: _s->cString
					       length: 1];

	return @".";
}

- (const of_unichar_t*)characters

Modified src/macros.h from [dcc14d0966] to [4a09bf3501].

112
113
114
115
116
117
118

119
120
121

122
123
124
125
126
127
128
		    __FILE__ ":%d:\n" #cond "\n", __LINE__);		\
		abort();						\
	}

#if !defined(_WIN32) && !defined(__DJGPP__)
# define OF_PATH_DELIMITER '/'
# define OF_PATH_DELIMITER_STRING @"/"

#else
# define OF_PATH_DELIMITER '\\'
# define OF_PATH_DELIMITER_STRING @"\\"

#endif
#define OF_PATH_CURRENT_DIRECTORY @"."
#define OF_PATH_PARENT_DIRECTORY @".."

extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL);
extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, signed char);








>



>







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
		    __FILE__ ":%d:\n" #cond "\n", __LINE__);		\
		abort();						\
	}

#if !defined(_WIN32) && !defined(__DJGPP__)
# define OF_PATH_DELIMITER '/'
# define OF_PATH_DELIMITER_STRING @"/"
# define OF_IS_PATH_DELIMITER(c) (c == '/')
#else
# define OF_PATH_DELIMITER '\\'
# define OF_PATH_DELIMITER_STRING @"\\"
# define OF_IS_PATH_DELIMITER(c) (c == '\\' || c == '/')
#endif
#define OF_PATH_CURRENT_DIRECTORY @"."
#define OF_PATH_PARENT_DIRECTORY @".."

extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL);
extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, signed char);