Differences From Artifact [2267fdd898]:
- File
src/OFURL.m
— part of check-in
[e164def279]
at
2013-02-08 22:20:18
on branch trunk
— OFURL: Improve -[description].
Before, it was not clear that the object is an OFURL, which could make
debugging hard. (user: js, size: 10721) [annotate] [blame] [check-ins using]
To Artifact [fcf898c186]:
- File src/OFURL.m — part of check-in [e40729d406] at 2013-02-12 18:22:15 on branch trunk — Prefix all ivars with an underscore. (user: js, size: 10714) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
63 64 65 66 67 68 69 | @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: [string UTF8StringLength]]; UTF8String = UTF8String2; if (!strncmp(UTF8String, "file://", 7)) { | | | | | | | | | | | | | | | | | | | | | | | | 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 | @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: [string UTF8StringLength]]; UTF8String = UTF8String2; if (!strncmp(UTF8String, "file://", 7)) { _scheme = @"file"; _path = [[OFString alloc] initWithUTF8String: UTF8String + 7]; return self; } else if (!strncmp(UTF8String, "http://", 7)) { _scheme = @"http"; UTF8String += 7; } else if (!strncmp(UTF8String, "https://", 8)) { _scheme = @"https"; UTF8String += 8; } else @throw [OFInvalidFormatException exceptionWithClass: [self class]]; if ((tmp = strchr(UTF8String, '/')) != NULL) { *tmp = '\0'; tmp++; } if ((tmp2 = strchr(UTF8String, '@')) != NULL) { char *tmp3; *tmp2 = '\0'; tmp2++; if ((tmp3 = strchr(UTF8String, ':')) != NULL) { *tmp3 = '\0'; tmp3++; _user = [[OFString alloc] initWithUTF8String: UTF8String]; _password = [[OFString alloc] initWithUTF8String: tmp3]; } else _user = [[OFString alloc] initWithUTF8String: UTF8String]; UTF8String = tmp2; } if ((tmp2 = strchr(UTF8String, ':')) != NULL) { void *pool; OFString *portString; *tmp2 = '\0'; tmp2++; _host = [[OFString alloc] initWithUTF8String: UTF8String]; pool = objc_autoreleasePoolPush(); portString = [OFString stringWithUTF8String: tmp2]; if ([portString decimalValue] > 65535) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; _port = [portString decimalValue]; if (_port == 0) _port = 80; objc_autoreleasePoolPop(pool); } else { _host = [[OFString alloc] initWithUTF8String: UTF8String]; if ([_scheme isEqual: @"http"]) _port = 80; else if ([_scheme isEqual: @"https"]) _port = 443; else assert(0); } if ((UTF8String = tmp) != NULL) { if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; _fragment = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; _query = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, ';')) != NULL) { *tmp = '\0'; _parameters = [[OFString alloc] initWithUTF8String: tmp + 1]; } _path = [[OFString alloc] initWithFormat: @"/%s", UTF8String]; } else _path = @""; } @catch (id e) { [self release]; @throw e; } @finally { free(UTF8String2); } |
︙ | ︙ | |||
187 188 189 190 191 192 193 | return [self initWithString: string]; self = [super init]; @try { char *tmp; | | | | | | | | | | | | | | | 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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | return [self initWithString: string]; self = [super init]; @try { char *tmp; _scheme = [URL->_scheme copy]; _host = [URL->_host copy]; _port = URL->_port; _user = [URL->_user copy]; _password = [URL->_password copy]; if ((UTF8String2 = strdup([string UTF8String])) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: [string UTF8StringLength]]; UTF8String = UTF8String2; if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; _fragment = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; _query = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, ';')) != NULL) { *tmp = '\0'; _parameters = [[OFString alloc] initWithUTF8String: tmp + 1]; } if (*UTF8String == '/') _path = [[OFString alloc] initWithUTF8String: UTF8String]; else { void *pool; OFString *s; pool = objc_autoreleasePoolPush(); if ([URL->_path hasSuffix: @"/"]) s = [OFString stringWithFormat: @"%@%s", URL->_path, UTF8String]; else s = [OFString stringWithFormat: @"%@/../%s", URL->_path, UTF8String]; _path = [[s stringByStandardizingURLPath] copy]; objc_autoreleasePoolPop(pool); } } @catch (id e) { [self release]; @throw e; } @finally { |
︙ | ︙ | |||
273 274 275 276 277 278 279 | } return self; } - (void)dealloc { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | < < < | | | | | | | | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | } return self; } - (void)dealloc { [_scheme release]; [_host release]; [_user release]; [_password release]; [_path release]; [_parameters release]; [_query release]; [_fragment release]; [super dealloc]; } - (BOOL)isEqual: (id)object { OFURL *URL; if (![object isKindOfClass: [OFURL class]]) return NO; URL = object; if (![URL->_scheme isEqual: _scheme]) return NO; if (![URL->_host isEqual: _host]) return NO; if (URL->_port != _port) return NO; if (URL->_user != _user && ![URL->_user isEqual: _user]) return NO; if (URL->_password != _password && ![URL->_password isEqual: _password]) return NO; if (![URL->_path isEqual: _path]) return NO; if (URL->_parameters != _parameters && ![URL->_parameters isEqual: _parameters]) return NO; if (URL->_query != _query && ![URL->_query isEqual: _query]) return NO; if (URL->_fragment != _fragment && ![URL->_fragment isEqual: _fragment]) return NO; return YES; } - (uint32_t)hash { uint32_t hash; OF_HASH_INIT(hash); OF_HASH_ADD_HASH(hash, [_scheme hash]); OF_HASH_ADD_HASH(hash, [_host hash]); OF_HASH_ADD(hash, (_port & 0xFF00) >> 8); OF_HASH_ADD(hash, _port & 0xFF); OF_HASH_ADD_HASH(hash, [_user hash]); OF_HASH_ADD_HASH(hash, [_password hash]); OF_HASH_ADD_HASH(hash, [_path hash]); OF_HASH_ADD_HASH(hash, [_parameters hash]); OF_HASH_ADD_HASH(hash, [_query hash]); OF_HASH_ADD_HASH(hash, [_fragment hash]); OF_HASH_FINALIZE(hash); return hash; } - copy { OFURL *copy = [[[self class] alloc] init]; @try { copy->_scheme = [_scheme copy]; copy->_host = [_host copy]; copy->_port = _port; copy->_user = [_user copy]; copy->_password = [_password copy]; copy->_path = [_path copy]; copy->_parameters = [_parameters copy]; copy->_query = [_query copy]; copy->_fragment = [_fragment copy]; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString*)scheme { OF_GETTER(_scheme, YES) } - (void)setScheme: (OFString*)scheme { if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; OF_SETTER(_scheme, scheme, YES, 1) } - (OFString*)host { OF_GETTER(_host, YES) } - (void)setHost: (OFString*)host { OF_SETTER(_host, host, YES, 1) } - (uint16_t)port { return _port; } - (void)setPort: (uint16_t)port { _port = port; } - (OFString*)user { OF_GETTER(_user, YES) } - (void)setUser: (OFString*)user { OF_SETTER(_user, user, YES, 1) } - (OFString*)password { OF_GETTER(_password, YES) } - (void)setPassword: (OFString*)password { OF_SETTER(_password, password, YES, 1) } - (OFString*)path { OF_GETTER(_path, YES) } - (void)setPath: (OFString*)path { if (([_scheme isEqual: @"http"] || [_scheme isEqual: @"https"]) && ![path hasPrefix: @"/"]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; OF_SETTER(_path, path, YES, 1) } - (OFString*)parameters { OF_GETTER(_parameters, YES) } - (void)setParameters: (OFString*)parameters { OF_SETTER(_parameters, parameters, YES, 1) } - (OFString*)query { OF_GETTER(_query, YES) } - (void)setQuery: (OFString*)query { OF_SETTER(_query, query, YES, 1) } - (OFString*)fragment { OF_GETTER(_fragment, YES) } - (void)setFragment: (OFString*)fragment { OF_SETTER(_fragment, fragment, YES, 1) } - (OFString*)string { OFMutableString *ret = [OFMutableString stringWithFormat: @"%@://", _scheme]; if ([_scheme isEqual: @"file"]) { if (_path != nil) [ret appendString: _path]; return ret; } if (_user != nil && _password != nil) [ret appendFormat: @"%@:%@@", _user, _password]; else if (_user != nil) [ret appendFormat: @"%@@", _user]; if (_host != nil) [ret appendString: _host]; if (([_scheme isEqual: @"http"] && _port != 80) || ([_scheme isEqual: @"https"] && _port != 443)) [ret appendFormat: @":%u", _port]; if (_path != nil) [ret appendString: _path]; if (_parameters != nil) [ret appendFormat: @";%@", _parameters]; if (_query != nil) [ret appendFormat: @"?%@", _query]; if (_fragment != nil) [ret appendFormat: @"#%@", _fragment]; [ret makeImmutable]; return ret; } - (OFString*)description |
︙ | ︙ |